Changing a dates format...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DynamiteHost
Forum Commoner
Posts: 69
Joined: Sat Aug 10, 2002 5:33 pm

Changing a dates format...

Post 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?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

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

or you could try exploding the string and handling each part...
DynamiteHost
Forum Commoner
Posts: 69
Joined: Sat Aug 10, 2002 5:33 pm

Post by DynamiteHost »

I'm having difficulty understanding that page :cry:

Could you whip up some code for me quickly... please? :D
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Well, I just tried strtotime and it didn't work..

its going to be really hard to do it now..
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
DynamiteHost
Forum Commoner
Posts: 69
Joined: Sat Aug 10, 2002 5:33 pm

Post by DynamiteHost »

ok, thanks for all your help (yet again) :D
Post Reply