I need to convert date string into number:
2012-Sep-01 to 2012-09-01
Any idea? Regards,
I need to convert date string into number:
2012-Sep-01 to 2012-09-01
Any idea? Regards,
This might work for you:
echo date("Y-m-d", strtotime($yourCurrentDateVat))'
PHP website is down at the moment, but here is some extra info on the date function.
Try to use DateTime PHP class:
$date = "2012-Sep-01";
$result = DateTime::createFromFormat("Y-M-d", $date)->format("Y-m-d");
$date = DateTime::createFromFormat('Y-M-j', '2012-Sep-01');
echo $date->format('Y-m-d');
Actually stolen from the manual: http://us.php.net/manual/en/datetime.createfromformat.php
You should use strtotime()
. More info on here. And then date()
to create a new string. More info on that here.
$date = '2012-Sep-01'; //Sets your date string
$time_epoch = strtotime($date); //Converts the string into an epoch time
$new_date = date('Y-m-d', $time_epoch); //Creates a new string
Hi, try using this in PHP and you will surely get what you want, I was searching for the same but didn't found but later discovered I had the date-time formula used somewhere and modified it to get this.
$getdatetime=date_create('2020-May-21');
$dateconverted=date_format($getdatetime,'Y-m-d');
echo $dateconverted;