[SOLVED] date representation

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
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

[SOLVED] date representation

Post 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>";

?>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

how about:

Code: Select all

$db_year_expanded = date('Y',mktime(0,0,0,$yyyy,1,1));
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post 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)); 
?>
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply