Encodera

Thanks for reading!

Donate to the site — we work hard for you.

How to get the current date and time

Short answer

The date() function returns the current date in the needed format:

<?php
 
echo date('d.m.Y H:i');

A date object

An object is handier for calculations:

<?php
 
$now = new DateTimeImmutable();
 
echo $now->format('Y-m-d');

The time zone

The time depends on the zone. Set it explicitly, otherwise PHP uses UTC:

<?php
 
$moscow = new DateTimeImmutable('2025-01-30 12:00', new DateTimeZone('UTC'));
 
echo $moscow->setTimezone(new DateTimeZone('Europe/Moscow'))->format('H:i');

Output:

15:00

Functions used in this recipe

  • date — Formats a date and time.
  • time — Returns the current timestamp.
  • DateTimeImmutable — A date and time object that cannot be changed: every operation returns a new object.

Thanks for reading!

Donate to the site — we work hard for you.