Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Minutes in DateTime?

Tags:

php

datetime

In jQuery are function to set Minutes, Hours etc. Is this also in PHP?

I have:

$date = new DateTime();

and

$min = '23';

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

Is possible? If yes, how?

like image 530
Mark Fondy Avatar asked Jan 17 '12 01:01

Mark Fondy


1 Answers

You are looking for DateTime::setTime.

If you want to modify the minutes and leave the hours untouched, you will of course have to pass the current hours value as the first parameter. Get that one with $dateTime->format('G').

like image 50
Jon Avatar answered Nov 06 '22 12:11

Jon