Re: DATE / strtotime

From: Date: Mon, 20 Apr 2009 03:29:31 +0000
Subject: Re: DATE / strtotime
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-291672@lists.php.net to get a copy of this message
Ron Piggott wrote:
Where $date_reference is 2009-04-18 the following code gives me a day of 1969-12-30. How do I get it to be 2009-04-17? $previous_date = strtotime("-1 days", $date_reference); $previous_date = date('Y-m-d', $previous_date); echo $previous_date; outputs 1969-12-30 Ron
You need to read the strtotime page in the manual. http://php.net/strtotime It says that the second argument of the strtotime function is suppose to be a unix time stamp. Is the value that you gave us for $date_reference a unix time stamp? No Your code should be like this. // This converts 2009-04-19 00:00:00 into 1240099200 $date_reference_unix = strtotime($date_reference); $previous_date = strtotime("-1 days", $date_reference_unix); $previous_date = date('Y-m-d', $previous_date); echo $previous_date; outputs 1969-12-30 -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare

« previous php.general (#291672) next »