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
Asked
Active
Viewed 311 times
-1
-
1It's kinda insane to store dates in a database like that, use date/time datatypes for those columns – Mark Baker Mar 23 '15 at 10:03
-
datatype in db datetime and value 1/10/2013 12:00:00 AM – mohammad89 Mar 23 '15 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 Mar 23 '15 at 10:07
1 Answers
0
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)

Mark Baker
- 209,507
- 32
- 346
- 385
-
not work this eror Fatal error: Call to undefined method DateTime::createfromformat() – mohammad89 Mar 23 '15 at 10:09
-
1Then 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. – Mark Baker Mar 23 '15 at 10:11
-
-