Page 1 of 1
converting date/time of MySQL into GMT time/date
Posted: Wed Nov 18, 2009 9:35 pm
by lauthiamkok
Hi,
How can I convert the date and time from MySQL into something like this below,
last updated at 10:38 GMT, Sunday, 15 November 2009
Where I would like to have GMT - it is like ones in BBC news site,
http://news.bbc.co.uk/
this is the php code I use,
Code: Select all
<?php echo $row_page['pg_updated'];>
and the result is - 2009-11-19 02:47:02
thanks,
L
Re: converting date/time of MySQL into GMT time/date
Posted: Thu Nov 19, 2009 8:13 am
by iankent
a datetime column is, as you say, formatted yyyy-mm-dd hh:mm:ss. You can use PHPs date() function to format it as you want. E.g.:
Code: Select all
echo date('jS F Y', strtotime($sqldate));
which will output something like '19th November 2009'.
Have a look at php's date manual (
http://php.net/manual/en/function.date.php) for a full list of format strings
edit: updated code which was horrifically wrong lol :/ should now work
edit2: to include GMT, as you know your time is already being stored in GMT, simply output the string GMT yourself, e.g.
Code: Select all
echo date('H:i:s') . ' GMT on ' . date('jS F Y', strtotime($sqldate));
which should output something like '14:15:01 GMT on 19th November 2009'
hth
Re: converting date/time of MySQL into GMT time/date
Posted: Thu Nov 19, 2009 9:47 am
by lauthiamkok
iankent wrote:a datetime column is, as you say, formatted yyyy-mm-dd hh:mm:ss. You can use PHPs date() function to format it as you want. E.g.:
Code: Select all
echo date('jS F Y', strtotime($sqldate));
which will output something like '19th November 2009'.
Have a look at php's date manual (
http://php.net/manual/en/function.date.php) for a full list of format strings
edit: updated code which was horrifically wrong lol :/ should now work
edit2: to include GMT, as you know your time is already being stored in GMT, simply output the string GMT yourself, e.g.
Code: Select all
echo date('H:i:s') . ' GMT on ' . date('jS F Y', strtotime($sqldate));
which should output something like '14:15:01 GMT on 19th November 2009'
hth
Yes I think my time is being store in GMT (I guess... ) so I just include 'GMT' in the output haha - simple as that! thanks!
