Skip to content

Core\Time\DateTime::minute

$dateTime->minute(): uint

Returns the minute of a date and time, as a uint from 0 to 59.

The minute is read in the time zone of the value. Most zones are a whole number of hours from UTC, so the minute is the same as in UTC. Some zones are not. At 10:15 UTC, minute returns 15 in UTC and 45 in India, which is 5 hours and 30 minutes ahead.

The result has the same name and type as the minute option of with. So $d->with({ minute: 0 }) gives the start of the same hour. The minute option must be from 0 to 59, and a value outside that range throws a RuntimeError.

Good to know: $d->minute() % 15 gives the minutes since the last quarter hour.

Return value

Returns uint. The minute, from 0 to 59.

Changelog

VersionChange
0.0.5Core\Time\DateTime::year, Core\Time\DateTime::month, Core\Time\DateTime::day, Core\Time\DateTime::hour, Core\Time\DateTime::minute, Core\Time\DateTime::second and Core\Time\DateTime::nanoseconds return the parts of a date and time as numbers. Each one reads the clock in the zone of the value. Core\Time\DateTime::year returns an int, and the others return a uint.

Examples

Read the minute

<?nvs
// Shows how to read the minute of a date and time as a number.
var $departure = Core\Time\DateTime::fromIso('2024-08-12 07:45', 'Europe/Zurich');
// `minute` returns a `uint` from 0 to 59. This prints 45.
echo $departure->minute(), "\n";
// The train leaves at 7:45, so there are 15 minutes until 8:00. This prints 15.
echo 60 - $departure->minute(), "\n";
Output
45
15

Round down to a quarter hour

<?nvs
// Shows how to round a time down to the start of its quarter hour, for a booking calendar.
class Slot
{
public static function startOf(Core\Time\DateTime $time): Core\Time\DateTime
{
// `% 15` gives the minutes past the last quarter hour. 10:52 is 7 minutes past 10:45.
uint $minute = $time->minute();
return $time->with({ minute: $minute - $minute % 15, second: 0, nanoseconds: 0 });
}
}
var $zone = Core\Time\Zone::of('Europe/Oslo');
// This prints 10:45, 10:00 and 23:30.
echo Slot::startOf(Core\Time\DateTime::fromIso('2024-02-09 10:52:18', $zone))->format('HH:mm'), "\n";
echo Slot::startOf(Core\Time\DateTime::fromIso('2024-02-09 10:00', $zone))->format('HH:mm'), "\n";
echo Slot::startOf(Core\Time\DateTime::fromIso('2024-02-09 23:44', $zone))->format('HH:mm'), "\n";
Output
10:45
10:00
23:30

A zone with a half hour offset

<?nvs
// Shows that the minute can be different in a time zone that is not a whole number of hours from UTC.
var $moment = Core\Time\Instant::fromIso('2024-03-05T10:15:00Z');
// In UTC the minute is 15.
echo $moment->in('UTC')->minute(), "\n";
// India is 5 hours and 30 minutes ahead of UTC. The time there is 15:45, so this prints 45.
echo $moment->in('Asia/Kolkata')->minute(), "\n";
// Nepal is 5 hours and 45 minutes ahead of UTC. The time there is 16:00, so this prints 0.
echo $moment->in('Asia/Kathmandu')->minute(), "\n";
Output
15
45
0