Page 1 of 1

[SOLVED] date representation

Posted: Mon Jul 19, 2004 9:08 am
by gurjit
how can i represent the year "98","99","04" in the format "1998","1999","2004".

I store the two representation in a variable but want to convert it to a four digit representation. i tried the following but it wont work:

the data i pull is from a database field which stores the year in two digit format in a varchar field:

Code: Select all

<?php
$yyyy = "99";
$mytt = date("Y",strtotime($yyyy."/02/02"));
echo $mytt . "<br>";

?>

Posted: Mon Jul 19, 2004 9:26 am
by pickle
how about:

Code: Select all

$db_year_expanded = date('Y',mktime(0,0,0,$yyyy,1,1));

Posted: Mon Jul 19, 2004 9:33 am
by gurjit
thanks worked great, needed to change format to "m,d,y" and thats it.

Code: Select all

<?php
$db_year_expanded = date('Y',mktime(0,0,0,1,1,$yyyy)); 
?>

Posted: Mon Jul 19, 2004 11:31 am
by pickle
gurjit wrote:needed to change format to "m,d,y" and thats it.
D'OH!! Well, I'm tired, that's my excuse. Glad to hear it works.