Set minutes to DateTime?

JQuery has a function for setting minutes, hours, etc. Is this also in PHP?

I have:

$date = new DateTime(); 

and

 $min = '23'; 

I would like to set the minutes to $ min in $ date.

Maybe? If so, how?

+6
source share
2 answers

You are looking for DateTime::setTime .

If you want to change the minutes and leave the watch intact, you will of course have to pass the current value of the clock as the first parameter. Get this with $dateTime->format('G') .

+8
source

DateTime::modify() will be the beginning. Just read the documentation found here

+1
source

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


All Articles