Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Re: Convert different date formats to yyyy-mm-dd
Old 07-04-2012, 12:33 AM Re: Convert different date formats to yyyy-mm-dd
cov
Junior Talker

Posts: 1
Trades: 0
Very useful information - thank you. Does anyone know of a site that may show a step by step process to do a date format conversion on a mysql db with PHP? I created a database about 3 years ago using varchar just to use a mm-dd-yyyy format and now I'm wishing I'd used the native mysql format of yyyy-mm-dd.

I'm posting to an older thread but am hopeful it still gets picked up. :-)

TIA

[QUOTE=NullPointer;869159]I would convert the date string to a timestamp and then use date() to format it however I want
[php]
$date = 'mm/dd/yyyy';
$timestamp = strtotime($date);
cov is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-04-2012, 11:42 AM Re: Convert different date formats to yyyy-mm-dd
King Spam Talker

Posts: 1,091
Name: Paul W
Trades: 0
Just add a field for the date in the correct format and then do an update with a few substr's
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 07-04-2012, 05:52 PM Re: Convert different date formats to yyyy-mm-dd
miki86's Avatar
Extreme Talker

Posts: 239
Location: print_r($serbia);
Trades: 0
Correct mysql date format should be Y-m-d H:M:S not mm/dd/yyyy

Try strftime("%Y-%m-%d %H:%M:%S", strtotime($oldDate)) see what results you'll get.
miki86 is offline
Reply With Quote
View Public Profile
 
Old 07-10-2012, 05:46 PM Re: Convert different date formats to yyyy-mm-dd
Novice Talker

Posts: 7
Trades: 0
@miki86
Actually, DATE type format is just yyyy-mm-dd. DATETIME is yyyy-mm-dd hh:mm:ss, but the "hh:mm:ss" part can be omitted during inserts/updates.

@cov
To convert mm-dd-yyyy to yyyy-mm-dd:

PHP Code:
 $new_date preg_replace('/(.*?)\-(.*?)\-(.*)/''\3-\1-\2'$old_date); 
lafor is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Re: Convert different date formats to yyyy-mm-dd
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16408 seconds with 11 queries