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
Convert one date to anothe date type php
Old 12-31-2010, 04:57 AM Convert one date to anothe date type php
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi Guys,

Any ideas how i can convert dates like "Wed Nov 24 08:27:52 2010" to "2010-11-24 08:27:52"

So i can insert the orginal date into a mysql DB with the new date format

Thanks
Graham
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 12-31-2010, 05:23 AM Re: Convert one date to anothe date type php
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
No worries, Ive done a nasty hack that seems to work fine!

PHP Code:
# Format = Sat Dec 11 11:15:19 2010
# New format = 2010-12-31 10:08:00

$line "Sat Dec 11 11:15:19 2010 SOME OTHER ****TY DATA NOT NEEDED";
// Change date format
$time substr($line024); // Get date.
$chunks preg_split('/\s+/'$time);

$month $chunks[1];
switch (
$month){
        case 
"Jan":
                
$month "01";
        break;
        case 
"Feb":
                
$month "02";
        break;
        case 
"Mar":
                
$month "03";
        break;
        case 
"Apr":
                
$month "04";
        break;
        case 
"May":
                
$month "05";
        break;
        case 
"Jun":
                
$month "06";
        break;
        case 
"Jul":
                
$month "07";
        break;
        case 
"Aug":
                
$month "08";
        break;
        case 
"Sep":
                
$month "09";
        break;
        case 
"Oct":
                
$month "10";
        break;
        case 
"Nov":
                
$month "11";
        break;
        case 
"Dec":
                
$month "12";
        break;
}
$time "$chunks[4]-$month-$chunks[2] $chunks[3]";

// Now echos $time as 2010-12-22 17:06:51 for example :) YAY 
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 12-31-2010 at 05:24 AM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 12-31-2010, 05:33 AM Re: Convert one date to anothe date type php
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Use strtotime to convert the date to a timestamp and then use date to format it however you want:
PHP Code:
$time strtotime('Wed Nov 24 08:27:52 2010');
echo 
date('Y-m-d H:i:s'$time); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-31-2010, 07:41 AM Re: Convert one date to anothe date type php
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Quote:
Originally Posted by NullPointer View Post
Use strtotime to convert the date to a timestamp and then use date to format it however you want:
PHP Code:
$time strtotime('Wed Nov 24 08:27:52 2010');
echo 
date('Y-m-d H:i:s'$time); 

Cool, Would of been simpler
Was in a rush.

Might change it to the above.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Reply     « Reply to Convert one date to anothe date type php
 

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.32386 seconds with 12 queries