Web Hosting Talk







View Full Version : MySQL Timestamp Parsing


dTuesday
11-16-2002, 06:26 AM
I am trying to extract only the day out of a MySQL timestamp that I have queried from a DB. I have tried the following, but $cDay always equals Array ( [0] => 31 [1] => 31 [2] => 31 ), which is not correct, since $cDate equals Array ( [0] => 2002-11-01 00:00:00 [1] => 2002-11-09 00:00:00 [2] => 2002-11-30 00:00:00 ).



for ($j = 0; $j<mysql_num_rows($query2); $j++){
$results = mysql_fetch_array($query2);
if ($results["id"]){
$cId[$j] = $results["id"];
$cSub[$j] = $results["subject"];
$cDate[$j] = $results["stamp"];//may need to format this data for Flash
$cDay[$j] = date(j, $results["stamp"]);
}
}


Any ideas?

:confused:

Thnx for the help,

- D

poo
11-16-2002, 02:58 PM
$cDay[$j] = date('j', strtotime($results["stamp"]));

strtotime() converts ISO dates to unix timestamps which is what the date() function requires. You should also quote the 'j'.

dTuesday
11-16-2002, 03:51 PM
Hey, thanks I will give that a shot.

- D

dTuesday
11-17-2002, 05:06 AM
That worked like a charm!

Thank you,

- D