Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Problem in converting date format (https://www.warriorforum.com/programming/780283-problem-converting-date-format.html)

wpintegration 18th April 2013 05:29 AM

Problem in converting date format
 
Hii,


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

KirkMcD 18th April 2013 08:34 AM

Re: Problem in converting date format
 
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

jaimegm 18th April 2013 12:51 PM

Re: Problem in converting date format
 
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


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