Compare dates

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
lolo
Forum Newbie
Posts: 1
Joined: Wed Oct 02, 2002 4:55 pm

Compare dates

Post by lolo »

Hi,

I have 1 or 2 dates... I must compare to now...

the dates are taken from my bd (type DATE) ... How compare them ?

id like to do

if (!$date2) {
if ($date1 == date("Y-m-d")) {
.......
}
} else {
if (date("Y-m-d") between $date1 and $date2)) {
.......
}
}
}

}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

depending on what you're trying to achieve you might reverse the check by selecting only those records that match your criteria.
i.e. SELECT fromDate,toDate,... FROM ... WHERE Now() BETWEEN fromDate AND toDate.
If this is not possible you can always get something like 'the number of seconds since the Unix Epoch' and compare those values

http://www.php.net/manual/en/function.time.php
http://www.php.net/manual/en/function.strtotime.php
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
http://www.mysql.com/doc/en/Comparison_ ... ml#IDX1129
http://www.mysql.com/doc/en/Date_and_ti ... ml#IDX1299
Post Reply