date_diff not support d/m/Y format. Currently I using strtotime to convert date to m/d/Y but I want to know the way to change date_diff date format to d/m/Y ?
Thank you.
date_diff not support d/m/Y format. Currently I using strtotime to convert date to m/d/Y but I want to know the way to change date_diff date format to d/m/Y ?
Thank you.
You can use DateTime::createFromFormat
:
$date1 = DateTime::createFromFormat( 'd/m/Y', '14/05/2016' ); # oo style
$date2 = date_create_from_format( 'd/m/Y', '17/05/2016' ); # procedural style
$dateInterval = $date1->diff( $date2 );
or:
$dateInterval = date_create_from_format( 'd/m/Y', '14/05/2016' )->diff( date_create_from_format( 'd/m/Y', '17/05/2016' ) );