Log in

View Full Version : php date problem



sukanya.paul
01-09-2008, 08:52 AM
hi, i have a form in which the user has to enter a date in the format dd-mm-yyyy. it can be any date. i want to store the previous day in my database.
eg: if the date entered is 01-01-2009 then the new date that should be entered to data base should be 31-12-2008.
can some one pls help me with this.
thanks in advance..
suk..

tech_support
01-09-2008, 10:02 AM
$date = '31-12-2008';
$date = strtotime($date);
$date = $date-(3600*24) //Minus one day in seconds
echo date('d-m-Y',$date);

Twey
01-09-2008, 10:39 AM
A day isn't precisely 24 hours.
$date = date('Y-m-d', strtotime('2008-01-01 -1 days'));Use international date format where possible, it makes working with dates easier.