Jump to content

date conversion


Space Cowboy

Recommended Posts

Hey guys, I need a bit of help here with dates.

 

Im rebuilding a website (a CMS). Ive been given the existing database which I now need to input into the new CMS.

 

The dates (of the articles) are in this format "18/02/2006 16:32:57"

 

Im used to working with dates in this format "20061802163257" (from this format its easy to order (the articles) by dates etc).

How can I convert this date format (on the fly) to something more workable?

Link to comment
https://forums.phpfreaks.com/topic/59166-date-conversion/
Share on other sites

Add a column, say, "newdate" TYPE DATETIME, to the table

 

In this query below, substitute your date column name for "dmy" and run the query

UPDATE dates SET
newdate = CONCAT(SUBSTRING(dmy,7,4),'-', SUBSTRING(dmy,4,2), '-', SUBSTRING(dmy,1,2), ' ', SUBSTRING(dmy, 12,)

 

Drop existing date column. Rename the newdate column.

Link to comment
https://forums.phpfreaks.com/topic/59166-date-conversion/#findComment-293883
Share on other sites

thanks..... but that website was the first place I looked!!! But it doesnt answer my question.

 

I already have the date in the awkward format. I need to convert this into the traditional "20060522123353" format.

 

Are you sure?

 

<?php
$date = "05/22/2006 12:33:53";

$date = strtotime($date);
$new_date = date('Ymdhis', $date);

echo $new_date;
?>

Link to comment
https://forums.phpfreaks.com/topic/59166-date-conversion/#findComment-294285
Share on other sites

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.