Home > DeveloperSection > Forums > php dates off by one day
Ashish Pandey

Total Post:128

Points:898
Posted on    May-18-2013 1:14 AM

 PHP PHP 
Ratings:


 1 Reply(s)
 958  View(s)
Rate this:
Hi Everyone!

I am changing int(11) in a mysql database back into regular date formats (mm/dd/yyy) It is working fine except it appears to be one day behind. Any ideas on what could be causing this?

The code I am using to change it from int(11) to mm/dd/yyy is below: (yes it is part of a larger script, this is just the one line that includes the date.)

echo "<td>" . date('m/d/Y', $row['due_date']) . "</td>";
Wihout the td's:

echo date('m/d/Y', $row['due_date]);
In my particular testing it should be returning: 07/01/2013 and it is returning: 06/30/2013

Thanks in advance! 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-18-2013 8:24 AM

Hi Ashish!

How is the table getting populated? You need to check the server timezone and then while displaying it in date format add those number of hours and that should fix your problem.

e.g if the source is GMT and you are expecting dates to be in sync with PST, then you need to add/subtract couple of hours.

i.e

echo date('m/d/Y', $row['due_date]+$offset_in_seconds);

I hope it helpful for you.

Don't want to miss updates? Please click the below button!

Follow MindStick