London Smith London Smith - 1 year ago 67
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,


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download