A
amith
hi
I have written javascript for comparing two dates in US format and
finding out whether the start date is greater than the end date and
vice versa.
In this attempt i have instantiated the date object with the date
string which the user inputs from a pop up calendar.
somewhat like this..........
var startdate= new Date(document.MForm.startDate.value);
Where MForm = form name
startDate= The name of the TextField where i fetch the date
from the user
in the US format(MM/DD/YYYY).
All my compare logic is based on the US format dates, which is
somewhat like this..........
var startdate= new Date(document.MForm.startDate.value);
var enddate=new Date(document.MForm.endDate.value);
var today=new Date();
var one_day=1000*60*60*24;
var end_start_diff =
Math.ceil((enddate.getTime()-startdate.getTime())/(one_day));
if((end_start_diff < 0))
{
alert(" End date should be greater than Start date");
document.MForm.endDate.focus();
return(false);
}
this logic works fine with US dates. But i realised that the same
code would not work if I accpet UK format dates from the
user.......b'cos
new Date("02/11/2004") US Format (MM/DD/YYYY) gives Feb 11,
2004
but... new Date("11/02/2004") UK Format (DD/MM/YYYY) gives Nov 2,
2004
......and this is what is causing the problem.
The soln what i have thought is to change the UK format date to US
format in the date.
But i need to know if a Date Object in javascript can be instantiated
with the UK format of date as the parameter??
ex: new Date("11/02/2004") should gimme Feb 11, 2004. Is there any
method i can do this. If not what are the other easy methods to solve
this problem??
Thanks in advnace for helping.
Regards
Amith
I have written javascript for comparing two dates in US format and
finding out whether the start date is greater than the end date and
vice versa.
In this attempt i have instantiated the date object with the date
string which the user inputs from a pop up calendar.
somewhat like this..........
var startdate= new Date(document.MForm.startDate.value);
Where MForm = form name
startDate= The name of the TextField where i fetch the date
from the user
in the US format(MM/DD/YYYY).
All my compare logic is based on the US format dates, which is
somewhat like this..........
var startdate= new Date(document.MForm.startDate.value);
var enddate=new Date(document.MForm.endDate.value);
var today=new Date();
var one_day=1000*60*60*24;
var end_start_diff =
Math.ceil((enddate.getTime()-startdate.getTime())/(one_day));
if((end_start_diff < 0))
{
alert(" End date should be greater than Start date");
document.MForm.endDate.focus();
return(false);
}
this logic works fine with US dates. But i realised that the same
code would not work if I accpet UK format dates from the
user.......b'cos
new Date("02/11/2004") US Format (MM/DD/YYYY) gives Feb 11,
2004
but... new Date("11/02/2004") UK Format (DD/MM/YYYY) gives Nov 2,
2004
......and this is what is causing the problem.
The soln what i have thought is to change the UK format date to US
format in the date.
But i need to know if a Date Object in javascript can be instantiated
with the UK format of date as the parameter??
ex: new Date("11/02/2004") should gimme Feb 11, 2004. Is there any
method i can do this. If not what are the other easy methods to solve
this problem??
Thanks in advnace for helping.
Regards
Amith