function getMonthExceptions(){
$countTimeline = $_POST['hiddenCountTimeline'];
If($_POST['timeline_0Start']!=""){
$exceptionList = array();
for($d=0; $d<=2; $d++){
If($countTimeline<=$d){
$startTimeline = $_POST['timeline_' . $d . 'Start'];
$endTimeline = $_POST['timeline_' . $d . 'End'];
$begin = new DateTime($startTimeline);
$endUnmodified = new DateTime($endTimeline);
$end = $endUnmodified->modify( '+1 day' );
$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
foreach($daterange as $date){
array_push($exceptionList, $date->format("Y-m-d"));
}
}
}
return($exceptionList);
}
}
I use this function to get some dates from input fields and save them into an array.
My problem:
If I format $startTimeline
with new DateTime()
and print $begin
, I get this result, which is the given date (2017-02-01) and todays date two times (2017-02-16):
DateTime Object ( [date] => 2017-02-01 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Berlin ) DateTime Object ( [date] => 2017-02-16 12:45:32.000000 [timezone_type] => 3 [timezone] => Europe/Berlin ) DateTime Object ( [date] => 2017-02-16 12:45:32.000000 [timezone_type] => 3 [timezone] => Europe/Berlin )
But it should be like that:
DateTime Object ( [date] => 2017-02-01 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Berlin )
Any ideas?
Edit: Solved it by deleting If($countTimeline<=$d){
and putting $countTimeline
into the for-loop above.