Forum Moderators: coopster
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'] );
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
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]";