Page 1 of 1

Formating a timestamp from database

Posted: Thu Jan 15, 2004 3:24 pm
by LynneM
Using DreamweaverMX, PHP and MySQL/PHPadmin:

I'm trying to figure out how to use the "DATE_FORMAT('%Y,%m,%d')" to format my timestamp data coming from my database like "2004-01-01"....can't figure out the exact way to add the php code to my recordset data field so that it will work?

<?php echo $rs_requestview->Fields('request_date'); ?>

I've tried lots of things, still no luck.
Thanks!
Lynne

Posted: Thu Jan 15, 2004 4:17 pm
by Dr Evil
Try this :

Code: Select all

<?php
$query= "SELECT  DATE_FORMAT(date_field, '%W %D %M %Y') AS formatted_date FROM table";
?>
date_field is date type

'%W %M %Y' gives: Monday 4th November 2002

more here date_format

Dr Evil

Posted: Thu Jan 15, 2004 5:26 pm
by kettle_drum
Why not store the time in the database as the unix epoch - the number fo seconds since sometime in 1970. Then you can easily do searches on the data and display it however you like :)