Home > Enterprise >  how to skip certain 0 from date
how to skip certain 0 from date

Time:11-17

My date values look like this: 2021-10-09

I want to change the format to this: 9/10 ( skip year, skip 0 before the number and change - into /

$date = strtotime('2021-10-09');
$new_date = date('d-m', $date);
$new_date = str_replace('-','/',$new_date);
$new_date = str_replace('0','',$new_date);
echo $new_date // result: 9/1 (should be 9/10) 

So i need to find a way: if the 0 is behind another number, then DO NOT skip the 0

How can i do that?

CodePudding user response:

Use date('j/n', $date) and remove str_replace lines.

  • Related