Retrieving MySQL timestamp value and displaying as localtime

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
energylevel
Forum Newbie
Posts: 4
Joined: Mon Nov 08, 2004 5:11 am

Retrieving MySQL timestamp value and displaying as localtime

Post by energylevel »

How to output a MySQL UTC timestamp field to correct local time with daylight saving with PHP?

Local time is set in php.ini with: date.timezone = "Europe/London"

Confirmed set with: <?php echo date_default_timezone_get(); ?>

But when I echo the timestamp field it does not display correct UK time for the record (an hour behind correct UK time).

<?php echo date('jS F Y - g:ia', strtotime($row['Date'])); ?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Retrieving MySQL timestamp value and displaying as local

Post by requinix »

MySQL handles the timezone conversion for TIMESTAMPs for you, but of course you have to set the right timezone for that to work properly.
Post Reply