Forum Moderators: coopster

Message Too Old, No Replies

Help with dates

         

bodycount

11:19 am on Feb 28, 2007 (gmt 0)

10+ Year Member



What i want to do is to check that a product is still in the warranty period. Warrant period is 1 year.

So i get the shipdate from the data base and enter the ruturned date.

$SHIPDATE = '2006-05-10';
$RETURNDATE = '2007-02-28';

$INWAR = ($SHIPDATE - $RETURNDATE);

ECHO "$INWAR";

What is returned is -1.

I think it is only using the year out of the date and not all of it. Do i have to convert the date into another format. If so how?

adb64

11:50 am on Feb 28, 2007 (gmt 0)

10+ Year Member



You could use strtotime [php.net] to convert both dates to a Unix timestamp and then subtract these. The difference is the number of seconds between the dates, divide by 86400 to get # days. If you also have the dates as separate day, month, year variables also mktime [php.net] can be used to get a Unix timestamp.