Page 1 of 1

Playing with time stamps and mysql

Posted: Wed Feb 12, 2003 10:37 am
by aybra
I've been Playing with time stamps in php and mysql, more trying to pull them into php,

Code: Select all

<?php
$result1 = mysql_query($query1, $connection) or die(mysql_error());
echo '<table border="1">';
while ($row = mysql_fetch_assoc($result1)) {
$bob = $row["date"];
$dogy = date ('D \t\he dS of F, Y', mktime('$bob'));
echo '<tr><td>',$dogy,'</td></tr>';
}
echo '</table>';

?>
But I get the current time and stuff, not what i'm pulling off of mysql....

The time stamp I've been using is: 8,0,0,1,21,2003: wich is saved in a tinytext format in mysql and works fine when I use it like :

Code: Select all

<?php
$date = date ('D \t\he dS of F, Y', mktime(8,0,0,1,21,2003));
print("$date");
?>
and get :Tue the 21st of January, 2003:

Could some one tell me what i'm doing wrong please?

I know its something simple and basic.. but I've been beating my head against the wall trying to figure it out....


Thank you for the hand.

Posted: Wed Feb 12, 2003 11:54 am
by daven
Using Tinytext or any other string-based column will not work with mktime. The parameters for mktime are integers, not strings. Anything you store as tinytext is interpreted as a string.

A better solution would be to have your Date column be of type datetime. Then you could use date() to format it and not need mktime() at all.

Posted: Wed Feb 12, 2003 12:08 pm
by aybra
Funny thing now.....

Code: Select all

<?php
$date = date ('D \t\he dS of F, Y', "2003-01-21 08:00:00");

?>
Brings up :Wed the 31st of December, 1969:

any clues?

Posted: Wed Feb 12, 2003 12:52 pm
by aybra
Thank you.. I found what I was looking for.

Code: Select all

<?php
$query1= "SELECT UNIX_TIMESTAMP(`date`) AS time FROM `hours`";
$result1 = mysql_query($query1, $connection) or die(mysql_error());
echo '<table border="1">';
while ($row = mysql_fetch_assoc($result1)) {
$bob = $row["time"];
$dogy = date ('D \t\he dS of F, Y', "$bob");
echo '<tr><td>',$dogy,'</td></tr>';
}
echo '</table>';

?>