Forum Moderators: coopster

Message Too Old, No Replies

Date format in MySQL

Date format

         

vinitjain75

12:23 am on Dec 1, 2007 (gmt 0)

10+ Year Member



Hi,

I am not able to get the date displayed in the following format in the php page using MySql

dd-Mon-yy
30-Nov-07 or 01-Dec-2007

Please help.

Regards
VJ

phranque

5:48 am on Dec 1, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], vinitjain75!

you could use this in your sql:
SELECT DATE_FORMAT(date_column, '%e-%b-%y') AS formatted_date...

use %Y instead of %y for a 4 digit year.
use %d instead of %e if you always want 2 digits.

vinitjain75

9:42 am on Dec 1, 2007 (gmt 0)

10+ Year Member



Thank you!

Yes I was not using the as clause and that's why not able to move it an array.

Regards
VJ

ZeroFunk

4:43 am on Dec 2, 2007 (gmt 0)

10+ Year Member



Also note that it is not wise to handle dates and mathamatics through sql, for performance reasons. I recommend that you store the time stamd and simply format it with php after your run the query:

$today = date('Ymd',$timestamp); // example

phranque

8:33 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome back to WebmasterWorld, zulufoxtrot!
good point on the efficiency.
and that 4-1/2 year lurk has to be a record...