Man, do i have hard time with this one.... this is probably simple you will say.
I need to compare the received date of a product to see if this is a new product or not... simple ennough !
$purchdate = $db_field['DATEDEBUT'];// here DATEDEBUT is 2011-09-20
$strtoday = strtotime("now");
$isnewitem = strtotime($purchdate + 15);
if ($isnewitem >= $strtoday) {
$newstock = true;
} else {
$newstock = false;
}
here i want the product that are 15 days old or less to be selected as newstock. Looks like the +15 is not working here.
thanks.
Comparing 2 dates using strtotime()
Moderator: General Moderators
-
grabber_grabbs
- Forum Commoner
- Posts: 60
- Joined: Mon Oct 10, 2011 6:13 pm
Re: Comparing 2 dates using strtotime()
dates are tricky.
Let's convert everything to seconds:
That's it, I am sure you can take from here.
Let's convert everything to seconds:
Code: Select all
$purchdate = '2011-09-20';
$purchdate = strtotime($purchdate); // purchdate in seconds
$today = strtotime(date('Y-m-d')); // today in seconds
$diff = ($today - $purchdate)/(60*60*24); // converted to days
echo $diff;