What am i trying
Link: Get the first month of the month for a given set of dates.
I am trying to get the first Monday of the month based on data dates.
For example: Consider the dates 2013-08-02 00:00; 2013-09-05 00:00 2013-08-02 00:00; 2013-09-05 00:00 . Then the result will be 2013-08-05 00:00; 2013-09-02 00:00 2013-08-05 00:00; 2013-09-02 00:00 respectively.
I can do this up to this point, but dosenot saves the time component.
What I need
In the above example: if two datetimes contain a time value, say 2013-08-02 10:00; 2013-09-05 10:00 2013-08-02 10:00; 2013-09-05 10:00 . Then the exit should be 2013-08-05 10:00; 2013-09-02 10:00 2013-08-05 10:00; 2013-09-02 10:00 . But I get 2013-08-05 00:00; 2013-09-02 00:00 2013-08-05 00:00; 2013-09-02 00:00 from your code. What can I do to solve this problem?
the code
$test = new DateTime('2013-08-02 10:00'); echo $test->modify('first monday')->format('Ymd H:i');
source share