Hello all,
I have a timestamp field in my db.
When I display it I want to format it into yyyy-mm-dd H:I:S
But I get exatcly like its stored on the db yyyymmddhhiiss
just numbers with no spaces.
any ideas?
format timestamp
Moderator: General Moderators
Heres an example:
EDIT: Damn, he beat me to it. Well that ways a bit easier heh 
Code: Select all
<?php
include("header.php");
@mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM table_name WHERE option=$option";
$result=mysql_query($query) or die("Error: " . mysql_error());
$num = mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
//this is the part that creates the date format
$date=mysql_result($result,$i,"date");
$timestamp = strtotime($date);
$date_format = 'Y-mm-dd H:I:S';
$newdate = date($date_format, $timestamp);
echo $newdate; //outputs something like "2003-10-23 11:01:32"
}
?>Sorry guys,
Both ways don't work.
the date is not the only field i need from this query and if I try to use the query way I get null on the date field.
The second way with the date function and strtotime gives an error that it can't handle dates prior to 0000:00:00 or something...
am I doing something wrong?
Thanks
Both ways don't work.
the date is not the only field i need from this query and if I try to use the query way I get null on the date field.
The second way with the date function and strtotime gives an error that it can't handle dates prior to 0000:00:00 or something...
am I doing something wrong?
Thanks
I'm guessing it's the way you're fetching the results. Try
"SELECT id,name,desc,DATE_FORMAT(date, '%Y-%m-%d %H:%i:%s') AS nicedate FROM table" then use 'nicedate' the same way you use id, name and desc.
"SELECT id,name,desc,DATE_FORMAT(date, '%Y-%m-%d %H:%i:%s') AS nicedate FROM table" then use 'nicedate' the same way you use id, name and desc.
Last edited by markl999 on Thu Oct 23, 2003 10:40 am, edited 1 time in total.