Forum Moderators: coopster

Message Too Old, No Replies

formatting output of date / time

         

adammc

6:42 am on Aug 8, 2006 (gmt 0)

10+ Year Member



Hi Guys,

I am storing the date that an itmne was posted in my MYSQL DB in a datetime column (example - 2006-08-30 12:05:33).

How can I extract it and echo as: 30-08-06, 6:33 pm

I have tried using the code below but I assume it won't work cause my column isn't a timestamp. It's outputting the same date/time for all rows, a date back in 1969 :eek:

# make the expiry date human readable
$expirydate = date("d.m.y, g:i a", $row['expiry_date'] );

dreamcatcher

6:56 am on Aug 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi adammc,

To convert the data from the db, let MySQL do the work. The DATE_FORMAT [dev.mysql.com] function is what you need.


SELECT *,DATE_FORMAT(expiry_date, '%e-%m-%y, %h:%i %p') as e_date FROM table.....

Then use the 'e_date' variable.

dc

adammc

8:57 am on Aug 8, 2006 (gmt 0)

10+ Year Member



Hiya dreamcatcher,

thanks for the reply.

is this right cause I tried to echo the edate variable and it was blank

$query = "SELECT posting_id, vehicle_type, vehicle_make, year, buyers_city, buyers_state, condition, category, DATE_FORMAT(expiry_date, '%e-%m-%y, %h:%i %p') as e_date FROM postings WHERE buyers_id=$_SESSION[buyers_id]";

dreamcatcher

9:09 am on Aug 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, that should work ok. What does the rest of your code look like?

dc

adammc

11:11 pm on Aug 8, 2006 (gmt 0)

10+ Year Member



Hi Dreamcatcher,

I got i, I had stupidly tried to echo edate as $edate instead of like this:

' . $row['e_date'] . '

Thanks for your help:)

dreamcatcher

7:13 am on Aug 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anytime my friend,

dc