Welcome Guest, Not a member yet? Register   Sign In
Date comparison in javascript
#1

[eluser]gmahesha[/eluser]
Hello everyone.
i have doubt regarding the date comparison. my problem is...

In my php form, i have text fields where i am entering the from date, to date in a format specified by the MyClient Base(it uses CI). When i click the submit button, i need to check the date values. So, i am passing the from date, to date, current date and the date format( eg. "dd/mm/yyyy") to the javascript function. in this function i need to check these values.
But i dont know, how to check these values...may be i have to use "convert to time unit" etc....

Plz give me advice.


Thanks in advance.
#2

[eluser]Twisted1919[/eluser]
Well as far as i know,if you pass variables containing dates in any format, javascript Lng is smart enough to see which one of the two is greater .
But you can send all the data to be processed on server side , and use php's strtotime function to convert the date in unix time , so a comparision between two timestamps will be more obvious .
Code:
$dateA = '11/11/2011';
$dateB = '12/10/2008';
$dateA = strtotime($dateA);
$dateB = strtotime($dateB);
if( $dateA > $dateB )
   {
   //...
   }




Theme © iAndrew 2016 - Forum software by © MyBB