I need convert month Name to month number and datetime to date date come from sql 1/oct/2013 0:00 need to convert 1/10/2013 how? Very Thanks
3
-
1It's kinda insane to store dates in a database like that, use date/time datatypes for those columnsMark Baker– Mark Baker2015-03-23 10:03:08 +00:00Commented Mar 23, 2015 at 10:03
-
datatype in db datetime and value 1/10/2013 12:00:00 AMmohammad89– mohammad892015-03-23 10:05:29 +00:00Commented Mar 23, 2015 at 10:05
-
If the database holds a datetime, then why do you have this obscure format with a month name that you need to convert?Mark Baker– Mark Baker2015-03-23 10:07:24 +00:00Commented Mar 23, 2015 at 10:07
Add a comment
|
1 Answer
Showing how to convert dates from one format to another is duplicated many times here on SO
$date = DateTime::CreateFromFormat('j/M/Y', '1/oct/2013');
echo $date->format('d/m/Y');
EDIT
If you absolutely can't update from a version of PHP that has been end of life since 6th January 2011, then you can convert your format to a slightly more regular format that will be recognised by strtotime()
$date = strtotime(str_replace('/','-','1/oct/2013'));
echo date('Y-m-d', $date), PHP_EOL;
But I'd strongly recommend updating your version of PHP.... or at least telling people what version you're running when you ask questions (because it makes a lot of difference to the answers you'll get)
4 Comments
mohammad89
not work this eror Fatal error: Call to undefined method DateTime::createfromformat()
Mark Baker
Then you're using a pretty old version of PHP: ConvertFromFormat() was introduced in version 5.3.0..... what version of PHP are you using? And you do realise that it's not a version that's supported any more.
mohammad89
I am used php5.2.9-2
mohammad89
Very Thanks Mark Baker it work prefect