Formating a timestamp from database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
LynneM
Forum Newbie
Posts: 4
Joined: Thu Jan 15, 2004 3:24 pm
Location: Pensacola, FL

Formating a timestamp from database

Post 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
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post 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
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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 :)
Post Reply