View Full Version : Re-Formatting a Date

04-07-2003, 06:48 AM
I am extracting a date from the database and it comes out in the format yyyy-mm-dd. In my page I would like to be able to refer to all three parts of this date as seperate variable.

I know how to format the current date using date() and I know how to format the results within the SQL select. My issue is reformatting a date from 'yyyy-mm-dd' to 'dd-mm-yy' or to just 'yyyy' etc.

Can this just done through php with some kind of function which does this?


04-07-2003, 08:54 AM
Why not post this in the PHP forum?

Anyway, this tell you all you need + it's the best site to look up this sort a thing (in addition to the PHP forum):D


Look for his usercomment. Think it's exactly what you need.
dontspam at technohac dot com
16-Apr-2002 10:47

04-07-2003, 12:01 PM
Thanks raf, originally I thought this was going to be an SQL question as it involved extracting data in the correct format but indeed it ended up as a 100% php question... in the end explode("-",dataFromMySQL) solved my problem :)

04-07-2003, 01:07 PM
it is indeed a PHP query...

for reference, here's a little function i made that will wort out YYMMDD into dd-mm-yy

function rfixdate($date)
$year = substr($date,0,2);
$month = substr($date,2,2);
$day = substr($date,4,4);
return $day."/".$month."/".$year;

I'll move this to the PHP forum too :)