Php Date() help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lhua059
Forum Newbie
Posts: 6
Joined: Fri Apr 14, 2006 11:23 pm

Php Date() help

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
lhua059
Forum Newbie
Posts: 6
Joined: Fri Apr 14, 2006 11:23 pm

Post 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..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply