Created
April 16, 2021 14:08
-
-
Save Asetss/53ed5e35ad30265682f8255d96c50490 to your computer and use it in GitHub Desktop.
case1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$case1 = '[ | |
{ | |
"from":"03/01/2021", | |
"to":"03/06/2021" | |
}, | |
{ | |
"from":"03/10/2021", | |
"to":"03/15/2021" | |
}, | |
{ | |
"from":"03/20/2021", | |
"to":"03/25/2021" | |
} | |
]'; | |
$arrDate = json_decode($case1, true); | |
$parsed_date = []; | |
foreach ($arrDate as $key => $date) { | |
$month = date("M", strtotime($date['from'])); | |
if(!isset($parsed_date[$key])) { | |
$parsed_date[] = $month; | |
} | |
if(isset($parsed_date[$key])) { | |
$from = new DateTime($date['from']); | |
$to = new DateTime($date['to']); | |
$parsed_date[] = $from->format('d') .'-'. $to->format('d'); | |
} | |
} | |
var_dump($parsed_date); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment