Page 1 of 1

Changing a dates format...

Posted: Sun Nov 24, 2002 11:02 am
by DynamiteHost
Ok... so I have this:

Code: Select all

<?
$date = "24 11 02";
?>
Its in DD MM YY format.

I need it to print 24th November 2002 instead...

How could I do this?

Posted: Sun Nov 24, 2002 11:10 am
by hob_goblin
http://www.php.net/manual/en/function.strtotime.php

or you could try exploding the string and handling each part...

Posted: Sun Nov 24, 2002 11:15 am
by DynamiteHost
I'm having difficulty understanding that page :cry:

Could you whip up some code for me quickly... please? :D

Posted: Sun Nov 24, 2002 11:47 am
by hob_goblin
Well, I just tried strtotime and it didn't work..

its going to be really hard to do it now..

Posted: Sun Nov 24, 2002 11:54 am
by hob_goblin

Code: Select all

<? 
$date = "24 11 02"; 
$date = explode(" ", $date);
if(substr($date&#1111;'2'], 0, 1) == "0")&#123;
 $date&#1111;'2'] = "20".$date&#1111;'2'];
 &#125; else &#123;
 $date&#1111;'2'] = "19".$date&#1111;'2'];
 &#125;
$date = implode(" ", $date);

function str2date($in)&#123;

$t = split("/",$in);
if (count($t)!=3) $t = split("-",$in);
if (count($t)!=3) $t = split(" ",$in);

if (count($t)!=3) return -1;

if (!is_numeric($t&#1111;0])) return -1;
if (!is_numeric($t&#1111;1])) return -2;
if (!is_numeric($t&#1111;2])) return -3;

if ($t&#1111;2]<1902 || $t&#1111;2]>2037) return -3;

return mktime (0,0,0, $t&#1111;1], $t&#1111;0], $t&#1111;2]);
&#125;

echo date("dS F Y", str2date($date));
?>
it will work for 10 years... its a little y2k bug, because you put the year in only two digits.

Posted: Sun Nov 24, 2002 11:59 am
by DynamiteHost
ok, thanks for all your help (yet again) :D