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)) {
.......
}
}
}
}
Compare dates
Moderator: General Moderators
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
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