...

View Full Version : Re-Formatting a Date



Candrias77
04-07-2003, 05: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?

Thanks

raf
04-07-2003, 07: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

http://www.php.net/manual/en/function.strtotime.php


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

Candrias77
04-07-2003, 11:01 AM
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 :)

Jeewhizz
04-07-2003, 12: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 :)

Jee



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum