Is there a short way to change the DateTime to "today" but save the previous saved time?

There is a DateTime object. I want to install it today and save time.

For instance:

  • It is installed on 2012-10-12 10:30:00
  • he should become 2012-11-22 10:30:00

This will not work, of course:

 // this obviously changes it to 2012-11-22 00:00:00 $date->modify('today')); 

This will work, but it looks like it will be a little more effort:

 $clone = clone $date(); $date->modify('today')->setTime($clone->format('H'), $clone->format('i')); 

Is there a shorter / more efficient way?

+4
source share
1 answer

Not much better:

 $newDate = new DateTime('today '.$date->format('H:i')); 
+6
source

Source: https://habr.com/ru/post/1447622/


All Articles