Forum Moderators: coopster

Message Too Old, No Replies

date validation gone wrong!

         

nshack31

2:52 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



My date/time validation was working fine when month was stored as a string (eg January), it then worked using the following....


$date_to_compar = strtotime($day.' '.$month.' '.$year.' '.$hour.':'.$minute.' '.$ampm);

$today=time();

if($today > $date_to_compar)
{
//do action
}

where day = 1 to 30, month = January to december, year = eg 2005, hour = 12hr format, minute = minutes, ampm = am OR pm

Now that I have changed month to an integer i cannot get my code to work! Can anybody help?! why did this work when month was a string but wont work now month is an integer? Im lost

Thanks!

adb64

4:04 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



When you pass e.g. the string 01 03 2005, strtotime can not determine whether you mean January 3 2005 or March 1 2005. Difference between US/EU date formats.

nshack31

4:08 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



so i can use strtotime when month is eg february but not if month is 2?

How else can I sort this problem? thanks!

..edit just tried mktime but it does not like the am pm I use which is needed because my clock is 12hr format

adb64

4:14 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



Yes, only when date in unambiguous it can determine. So 05 23 2005 will resolve to May 23 2005 as there is no 23rd month.
Maybe it helps adding a / between the date (US format) when you mean month date year or a - (EU format) when you mean date month year. I never tried this, maybe strtotime has this intelligence, but I couldn't find it anywhere in the documentation.

nshack31

4:28 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



The strtotime code im using doesnt seem to be taking time into account only The date. Im very confused, when month was a string it worked fine

adb64

4:41 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



I found a link from the PHP help page to [gnu.org...]
maybe you can try that and see if it solves your problem. Beware that month, date, hour and minute must all be two digits. So prefix the value with a 0 when < 10.

nshack31

4:45 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



I'll try that thanks!