London Smith London Smith - 1 month ago 14
PHP Question

Recover two dates which are betweens 2 brackets []

I got a string with two dates between 2 brackets and separated by a comma like that:


How to recover these dates and put them in two variables,



Assuming you obtain as a string you can use explode

 $myStartString = "[2016-09-07],[2016-11-16]";

if you need you can remove the brackets this way

 $remove = ['[',']'];
 $myString = str_replace( $remove, "", myStartString);


 $myArray = explode(',' $myString);

 $startDate = $myArray[0];
 $endDate = $myArray[1];

Or wihthout the brackets:

$myString = '2016-09-07,2016-11-16';
$myArray = explode(',', $myString);
$startDate = $myArray[0];
$endDate = $myArray[1];
echo $startDate. ' '.$endDate ;

But is better if you have a normalized database