How to convert date 14-Jun-2015 to 2015-06-14?

Hi,

I cannot seem to get a date like 14-Jun-2015 converted to 2015-06-14 using sc_date_conv().

Is there anyway other than parsing the date string and replacing the Jun with 06 and then converting using the macro?

Thanks

Tony

Hi,

try this code :

$date_type = DateTime::createFromFormat(‘d-M-Y’,‘14-Jun-2015’);
$new_date=date(‘Y-m-d’,$date_type->getTimestamp());
echo $new_date;

Thanks ionutberlea,

Thanks for your help. I ended up using the following code.

$_usr_expiry = htmlspecialchars($_GET[“suc_exp”]);
$_new_date = DateTime::createfromformat(‘d-M-Y’,$_usr_expiry);
$_usr_expiry = date_format($_new_date,‘Y-m-d’);

The first line captures the value from the url part ?sec_exp=14-Jun-2015
The second line is per your suggestion
The third line I changed from your suggestion as it was not converting properly for some reason.

Thankfully, it all now works.

Once again, thanks for your help

Tony