Skip to main content
Post Undeleted by Pieter Goosen
added 499 characters in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

EDIT

You should be using date_create_from_format or its alias DateTime::createFromFormat() to convert on format to another. You can try the following

$date = DateTime::createFromFormat('m-d-Y', '03-09-2015');
echo $date->format('d-m-Y');

This will convert 03-09-2015 to 09-03-2015

ORIGINAL ANSWER

This is more a PHP question than Wordpress question. You can simply use str_replace to change the / in your date to -. You are not changing the format, so no need for date_format or any other date related functions

You can try something like

$date = '03/09/2015';
$modified_date = str_replace( '/', '-', $date );
echo $modified_date;

This will output 03-09-2015

This is more a PHP question than Wordpress question. You can simply use str_replace to change the / in your date to -. You are not changing the format, so no need for date_format or any other date related functions

You can try something like

$date = '03/09/2015';
$modified_date = str_replace( '/', '-', $date );
echo $modified_date;

This will output 03-09-2015

EDIT

You should be using date_create_from_format or its alias DateTime::createFromFormat() to convert on format to another. You can try the following

$date = DateTime::createFromFormat('m-d-Y', '03-09-2015');
echo $date->format('d-m-Y');

This will convert 03-09-2015 to 09-03-2015

ORIGINAL ANSWER

This is more a PHP question than Wordpress question. You can simply use str_replace to change the / in your date to -. You are not changing the format, so no need for date_format or any other date related functions

You can try something like

$date = '03/09/2015';
$modified_date = str_replace( '/', '-', $date );
echo $modified_date;

This will output 03-09-2015

Post Deleted by Pieter Goosen
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

This is more a PHP question than Wordpress question. You can simply use str_replace to change the / in your date to -. You are not changing the format, so no need for date_format or any other date related functions

You can try something like

$date = '03/09/2015';
$modified_date = str_replace( '/', '-', $date );
echo $modified_date;

This will output 03-09-2015