Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 18th Apr 2013, 05:29 AM   #1
Warrior Member
 
Join Date: 2012
Location: India
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default
Problem in converting date format
Share on: 
fb share twitter share gplus share more share

Hii,


Can anybody tell me how can I convert the Date Format from 18/4/2013 to 2013-04-18 in the PHP?

Pleasure and action make the hours seem short. By : William Shakespeare
wpintegration is offline  
Unread 18th Apr 2013, 08:34 AM   #2
VIP Warrior
War Room Member
 
Join Date: 2006
Location: , , USA.
Posts: 1,795
Thanks: 70
Thanked 287 Times in 259 Posts
Default
Re: Problem in converting date format
Share on: 
fb share twitter share gplus share more share

Parse it and put it back together again and then reformat it.
Try this function for the first part:
PHP: date_parse_from_format - Manual
and read this for the rest
PHP: date_format - Manual
KirkMcD is offline  
Unread 18th Apr 2013, 12:51 PM   #3
HyperActive Warrior
 
Join Date: 2010
Posts: 130
Thanks: 7
Thanked 37 Times in 32 Posts
Default
Re: Problem in converting date format
Share on: 
fb share twitter share gplus share more share

function ChangeFormat($InputDate){

$TheDate=explode("/",$InputDate);
$TheDay=$TheDate[0];
$TheMonth=$TheDate[1];
$TheYear=$TheDate[2];

if (strlen($TheMonth)<2) $TheMonth="0".$TheMonth;
if (strlen($TheDay)<2) $TheDay="0".$TheDay;

return "$TheYear-$TheMonth-$TheDay";
} //ChangeFormat Ends

$IniDate="18/4/2013";
echo "Inital date is: $IniDate and Ending date format is: ".ChangeFormat($IniDate);


I hope this helps
jaimegm is offline  
Closed Thread


Bookmarks

Tags
converting, date, format, problem


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




All times are GMT -6. The time now is 08:22 AM.