To display Timestamp nicely
Moderator: General Moderators
To display Timestamp nicely
I read a date from db in timestamp(14) format(YYYYMMDDHHMMSS). What is the function in php should I use to display the date in nice format such as dd-mm-yyyy hh:mm:ss am/pm. I have tried strtotime, strftime, getDate function but it's not working. Can somebody help me to solve the problem. Thanks guys....

does strftime() work with a mysql timestamp? he said he tried it already.
just format your date in your query
i believe that's correct, if not search the manual for date_format
just format your date in your query
Code: Select all
mysql_query("SELECT *, DATE_FORMAT(date_col, '%d-%m-%Y %r') as date_col FROM table");-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
yea dusty is correct, using the date format in the mysql call uses less resources on your server, thats the way I'd go
but if you still wanna use a function you can do this
but if you still wanna use a function you can do this
Code: Select all
<?php
function timedate($date)
{
// start date routine from a timestamp field
$datefromdb = $date;
$year = substr($datefromdb,0,4);
$mon = substr($datefromdb,4,2);
$day = substr($datefromdb,6,2);
$date = $mon."/".$day."/".$year;
return $date;
}
?>I also always save timestamp as a VARCHAR in mysql, makes it easier to deal with later.
I use date() and format however it needs to be formatted for whatever I happen to be doing.
I use date() and format however it needs to be formatted for whatever I happen to be doing.
Code: Select all
<?php
where $time = your time column
$day_time = date("F j, Y, g:i a", $time);
prints this format-> August 19, 2002, 5:49 pm
?>