Working with dates in PHP
| From: | James Purser | Date: | Fri, 11 Oct 2002 05:53:55 +0000 |
| Subject: | Working with dates in PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-119601@lists.php.net to get a copy of this message | ||
I am at my wits end at the moment. I am pulling a datetimestamp out of a database and attempting to get the year month and day out of it. However I am stumped as how to do it.
The format is "YYYY-MM-DD HH:MM:SS" and its coming out of a mySQL database. Is there anyway I can get the information I need out of here?
I have tried $nday = date("d", $row[2]) and so on but all i get out of that is Year = 1970, Month = 01, Day = 01.
Heres the code Im using now with getdate()
while($row = mysql_fetch_row($fres))
{
print($row[2]);
$odate = getdate($row[2]);
print($odate['mday']."<br />");
$oday = date("d", $odate);
print($odate['mon']."<br />");
$omonth = date("m", $odate);
print($odate['year']."<br />");
$oyear = date("Y", $odate);
print($oyear."<br />");
}
Any help would be appreciated.
James