Home > Software design >  How to change excel timestamp format ? Format change but date is not correct
How to change excel timestamp format ? Format change but date is not correct

Time:02-12

$my = '13/02/2022 21:29:30';
$converted = date('d M Y h.i.s A', strtotime($my));
$reversed = date('d-m-Y H:i:s', strtotime($converted));
echo $reversed;

// output 01-01-1970 00:00:00

but I want a correct date

CodePudding user response:

you can use several solution .

solution #1

$var = '20/04/2012 21:29:30';
$date = str_replace('/', '-', $var);
echo date('Y-m-d', strtotime($date));

solution #2

$old_date = explode('/', '5/4/2010'); 
$new_data = $old_date[2].'-'.$old_date[1].'-'.$old_date[0];

solution #3

$var = '20/04/2012';
echo implode("-", array_reverse(explode("/", $var)));

CodePudding user response:

  • Create a DateTime Object from the string.
  • Then format the date!!
  • Happy Coding
  • Related