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
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
Share on other sites

thanks, I dont fully understand that query but I will give it a go!

 

...presuming this quesry understands this daft format the date it currently in? (ie 18/02/2007 16:40:53"). Infact ideally I could do to get rid of the time completly, and just convert to "20071802"

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.