Page 1 of 1

Php Date() help

Posted: Fri Apr 21, 2006 2:30 am
by lhua059
hi there, i wonder if there is any date() function i can use to test if two date ( in the same format) are equal? cheers!

Posted: Fri Apr 21, 2006 2:31 am
by feyd
Even easier:

Code: Select all

$foo == $bar;
Note that if they are non-numeric (ignoring symbols) or not in uniform dimensions (04 vs 4) You will get errors. If they vary, you need to convert them to unix timestamps.

Posted: Fri Apr 21, 2006 2:40 am
by lhua059
hi feyd..thanks for your reply
if given two day

Code: Select all

$day1=date("l d M",strtotime("+1 day")); // its in the format  like this -- Friday 21 Apr
 $day2=date("l d M",strtotime("+2 day"));

if($day1==$day2){
 some codes here..

}

is that what u mean?
i try that but it didn't work...
i am thinking if i should cast those two days to "String" and compare them..

Posted: Fri Apr 21, 2006 8:36 am
by feyd
The l (lower case L) in your date() call makes the comparison not work as it creates a non-numeric result.

Ymd or any version with symbols added can be compared without issue. If you run the dates through strtotime() (and they are read correctly) you can compare that result, generally.