Page 1 of 1
[solved] converting a mysql date to plain english with php
Posted: Tue Sep 20, 2005 9:10 pm
by robster
I'm stumped, I've spent the last half day browsing through php.net manuals looking at date function etc but can't seem to figure out how to convert my mysql date data which looks like this:
into something which looks like this:
I know this must seem such a sad call for help, but I'm stuck

(such a neub still, sigh).
Rob
Posted: Tue Sep 20, 2005 9:19 pm
by Charles256
you have to combine date and gmktime.
the general format of gmmktime is int gmmktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
to get sunday,02 June 2005 you'd have to do the following..
Code: Select all
date('l d F Y',gmmktime(0,0,0,06,02,2005))
that should do the trick unless i had a typo:-D
Posted: Tue Sep 20, 2005 9:41 pm
by Todd_Z
Code: Select all
$date = "2005-06-20";
$parts = explode( "-", $date );
$timestamp = mktime( 0, 0, 0, $parts[1], $parts[2], $parts[0] );
echo date( "l, d F Y", $timestamp );
Posted: Tue Sep 20, 2005 9:43 pm
by feyd
be careful with using 0 as a leading to numbers... php may think you mean octal notation

Posted: Tue Sep 20, 2005 9:59 pm
by robster
Thank you so much. It really works well (and turns out it's actually on a Thursday, not a Sunday

).
That explode bit of code is really nice. I'll look into that some more, a very useful function indeed!
I'm interested in what could happen if an 'octal notation' occured !? (sounds... so... medical)
rob
Posted: Tue Sep 20, 2005 10:48 pm
by feyd
Code: Select all
[feyd@home]>php -r echo((016).chr(13).(16).chr(13).(0x16));
14
16
22
Posted: Wed Sep 21, 2005 12:14 am
by ryanlwh
why not
Code: Select all
date('l, d F Y',strtotime($mysqlDate));