Jump to content

[SOLVED] Date Conversion In PHP


refiking

Recommended Posts

I am trying to display the m-d-Y format of a timestamp from a mysql db.  Here's my code:

 

while ($raw = mysql_fetch_assoc($dql)){
$date = $raw['exp_date'];
}
$time = time($date);
$exp = date("m-d-Y", $time);
Echo $date . '</br>' . $exp;

 

Here's what that returns:

 

2008-09-30 14:42:25

10-04-2008

Link to comment
https://forums.phpfreaks.com/topic/127080-solved-date-conversion-in-php/
Share on other sites

To output a DATE or DATETIME from a database in any format you want, such as m-d-y, use the mysql DATE_FORMAT() function in your query. Why convert to a Unix timestamp only to convert it back to something else when you can get the end result directly out of the query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.