Playing with time stamps and mysql

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
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Playing with time stamps and mysql

Post 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.
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post 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.
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post 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?
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

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

?>
Post Reply