Date and time formats cheat sheet

A date format determines how a point in time is written in a file, in a database, in an HTTP header, or in an API. This cheat sheet brings together the common standards, the format codes in PHP, MySQL, PostgreSQL, JavaScript, Python, and the date command, and how to handle time zones. You can search, filter by topic, and copy with a click.

Common standards and formats

  • 2026-11-29

    A date in ISO 8601 format: a four-digit year, then the month and the day, separated by hyphens. Ordering from the largest unit to the smallest prevents confusion between the day and the month, and sorting dates in this format alphabetically also sorts them chronologically.

    Example: YYYY-MM-DD

  • 2026-11-29T14:30:00Z

    A date and time in RFC 3339 format, a restricted profile of ISO 8601 used in APIs, JSON, and log files. The letter T separates the date from the time, and the letter Z indicates that the time is in UTC. The standard also allows a lowercase t and z.

    Example: YYYY-MM-DDTHH:MM:SSZ

  • 2026-11-29T16:30:00+02:00

    The same format with an offset from UTC instead of Z. The local time is 16:30, and the +02:00 offset shows that this is the same moment as 14:30 UTC. The offset is written in hours and minutes, with a colon between them.

    Example: 1996-12-19T16:39:57-08:00 = 1996-12-20T00:39:57Z

  • 2026-11-29T14:30:00.123Z

    Fractions of a second are written after a period, right after the seconds. RFC 3339 allows any number of digits. JavaScript always writes three digits, that is, milliseconds, and Python writes six digits, that is, microseconds, when there are fractions of a second.

    Example: 1985-04-12T23:20:50.52Z

  • 2026-11-29 14:30:00+02:00

    RFC 3339 allows replacing the letter T with a space for readability. This is how the date --rfc-3339=seconds command and PostgreSQL display the time. In APIs and JSON files, the convention is to use T, as defined by the grammar of the standard.

    Example: date --rfc-3339=seconds

  • -00:00

    Under the original RFC 3339, the -00:00 offset indicates that the time in UTC is known, but the offset of the local clock is unknown. RFC 9557 updated the standard: Z is now used for this meaning, while +00:00 indicates that UTC is the reference point of the time.

    Example: 2026-11-29T14:30:00-00:00 → 2026-11-29T14:30:00Z

  • 20261129T143000

    ISO 8601 also allows a form without hyphens and colons. RFC 3339 doesn't allow it, so in APIs the date and time are written with the separators.

    Example: 2026-11-29T14:30:00

  • PT2H30M

    A duration in ISO 8601 format. The letter P comes first, followed by years (Y), months (M), weeks (W), and days (D), and the letter T comes before hours (H), minutes (M), and seconds (S). The letter M before T means months, and after T it means minutes.

    Example: P40D | P3DT4H59M | PT2H30M

  • Sun, 06 Nov 1994 08:49:37 GMT

    The date format in HTTP headers such as Date and Last-Modified, called IMF-fixdate and defined in RFC 9110. The time is always in GMT, and the format is case-sensitive. A server must send only this form, and a recipient must also accept two obsolete formats.

    Example: Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT

  • Thu, 21 Dec 2000 16:01:07 +0200

    The date format in the Date header of an email message under RFC 5322: the day of the week (optional), the day, the abbreviated month name, the year, the time, and a four-digit offset from UTC without a colon. Date is one of the required headers in every message, and the standard recommends +0000 to indicate UTC.

    Example: date -R

  • 1700000000

    Unix timestamp: the number of seconds since January 1, 1970, at 00:00:00 UTC. The same number represents the same moment in every time zone, so it's well suited to storing and comparing points in time. A timestamp in seconds currently has 10 digits.

    Example: 1700000000 = 2023-11-14T22:13:20Z

  • 1700000000000

    A timestamp in milliseconds, such as the value Date.now() returns in JavaScript, has 13 digits. To convert it to seconds, divide by 1000 and round down. A value in milliseconds read as seconds results in a date very far in the future.

    Example: Math.floor(Date.now() / 1000)

  • 2147483647

    The highest value of a signed 32-bit integer, which corresponds to January 19, 2038, at 03:14:07 UTC. A system that stores timestamps in 32 bits can't store a later time, and in MySQL this is also the end of the range of the TIMESTAMP type.

    Example: date -u -d @2147483647

PHP date formats

  • date('Y-m-d H:i:s')

    The common format for a date and time. Y is a four-digit year, m the month and d the day with a leading zero, H the hour on a 24-hour clock, i the minutes, and s the seconds. The same characters are used in the format() method of DateTime.

    Example: 2026-11-29 14:30:00

  • date('d.m.Y')

    A date in day, month, year order. j and n show the day and the month without a leading zero, and G shows the hour without a leading zero.

    Example: date('j.n.Y G:i')

  • D / l / N

    D shows the day of the week as three letters, from Mon to Sun, the letter l (lowercase L) shows its full name, and N shows the ISO 8601 day number, from 1 (Monday) to 7 (Sunday).

    Example: date('l, d.m.Y')

  • U

    The number of seconds since January 1, 1970, UTC, that is, the Unix timestamp. The time() function returns the same value as an integer.

    Example: date('U') | time()

  • c

    A date and time in ISO 8601 format with the offset from UTC. This character works for years up to 9999.

    Example: 2004-02-12T15:19:21+00:00

  • r

    A date in RFC 2822 and RFC 5322 format, the format of the Date header in email messages.

    Example: Thu, 21 Dec 2000 16:01:07 +0200

  • e / T

    e shows the time zone identifier, for example UTC or Atlantic/Azores, and T shows its abbreviation, such as EST, or the offset from GMT when there's no known abbreviation.

    Example: date('H:i e')

  • P / O / p

    P shows the offset from GMT with a colon, O without a colon, and p works like P but shows Z when the offset is zero.

    Example: +02:00 | +0200 | Z

  • o-W

    W shows the ISO 8601 week number, with weeks starting on Monday, and o shows the year the week belongs to. In the last days of December, Y and o can differ, so use o together with W.

    Example: (new DateTimeImmutable('2024-12-30'))->format('o-W') = 2025-01

  • DateTimeInterface::ATOM

    A constant with the format Y-m-d\TH:i:sP, identical to RFC3339 and compatible with ISO 8601. The ISO8601 constant isn't compatible with ISO 8601 and is kept only for backward compatibility. For fractions of a second, use RFC3339_EXTENDED.

    Example: $dt->format(DateTimeInterface::ATOM)

  • gmdate('D, d M Y H:i:s \G\M\T')

    A date in the HTTP header format. gmdate() shows the time in GMT, and the backslash before G, M, and T outputs the letters as they are. The RFC7231 constant is deprecated in recent versions, and it also doesn't convert the time to GMT.

    Example: Sat, 30 Apr 2016 17:52:13 GMT

  • $dt->setTimezone(new DateTimeZone('Asia/Jerusalem'))

    Moves a DateTime object to another time zone by its name in the IANA database, so you can store the time in UTC and display it in local time.

    Example: $dt->setTimezone(new DateTimeZone('Asia/Jerusalem'))->format('d.m.Y H:i')

  • date_default_timezone_set('Asia/Jerusalem')

    Sets the time zone for all the date functions in the script, and returns false when the zone name isn't valid. Instead of calling it in every script, you can set date.timezone in php.ini.

    Example: date_default_timezone_get()

MySQL date formats

  • DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')

    Displays a date and time in a given format. In MySQL, the minutes are %i and the seconds %s, while %M shows the month name. %T is shorthand for the full time on a 24-hour clock, and %f shows microseconds.

    Example: 2026-11-29 14:30:00

  • DATE_FORMAT(created_at, '%d.%m.%Y')

    A date in day, month, year order. %e and %c show the day and the month without a leading zero, %H the hour on a 24-hour clock, and %h the hour on a 12-hour clock.

    Example: DATE_FORMAT(created_at, '%d.%m.%Y %H:%i')

  • %W / %a / %M / %b

    %W shows the name of the day of the week, %a its abbreviation, %M the month name, and %b its abbreviation. The language of the names is set by the lc_time_names variable.

    Example: DATE_FORMAT(NOW(), '%W %e %M %Y')

  • STR_TO_DATE('29.11.2026', '%d.%m.%Y')

    The inverse of DATE_FORMAT: converts a string to a date according to a format. Returns NULL with a warning when the string doesn't match the format.

    Example: 2026-11-29

  • UNIX_TIMESTAMP()

    Without an argument, returns the current timestamp in seconds. With a date, it interprets the date in the time zone of the connection and converts it to a timestamp.

    Example: UNIX_TIMESTAMP('2015-11-13 10:20:19')

  • FROM_UNIXTIME(1700000000)

    Converts a timestamp to a date and time in the time zone of the connection. A second argument takes a format, as in DATE_FORMAT.

    Example: FROM_UNIXTIME(1700000000, '%d.%m.%Y %H:%i')

  • UTC_TIMESTAMP()

    The current date and time in UTC, regardless of the time zone of the connection. NOW() returns the time in the time zone of the connection.

    Example: SELECT UTC_TIMESTAMP(), NOW();

  • SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;

    Shows the time zone of the server and of the current connection. The default value SYSTEM means that the server uses the time zone of the operating system.

    Example: SELECT @@system_time_zone;

  • SET time_zone = '+00:00';

    Sets the time zone of the current connection only, in the range from -13:59 to +14:00. The setting affects TIMESTAMP values and NOW(), and doesn't change DATETIME values, which are stored as entered.

    Example: SET time_zone = 'Asia/Jerusalem';

  • SELECT COUNT(*) FROM mysql.time_zone_name;

    Checks whether the time zone tables are loaded. A result of 0 means that the tables are empty, and then a zone name such as Asia/Jerusalem returns the error Unknown or incorrect time zone.

    Example: ERROR 1298 (HY000)

  • mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

    Loads the time zones from the time zone database of the operating system into the MySQL tables. After loading them, restart the database server so it doesn't use stale cached data.

  • CONVERT_TZ(created_at, '+00:00', 'Asia/Jerusalem')

    Converts a date and time value from one time zone to another. With fixed offsets, such as '+00:00', it works even without the time zone tables, while zone names require the tables. Returns NULL when one of the arguments isn't valid.

    Example: CONVERT_TZ('2004-01-01 12:00:00', '+00:00', '+10:00') = 2004-01-01 22:00:00

PostgreSQL date formats

  • to_char(now(), 'YYYY-MM-DD HH24:MI:SS')

    Displays a date and time in a given format. HH24 is the hour on a 24-hour clock, while HH alone is the hour on a 12-hour clock. MI is the minutes and SS the seconds.

    Example: 2026-11-29 14:30:00

  • to_char(now(), 'DD.MM.YYYY')

    A date in day, month, year order. The FM prefix removes the leading zero and the padding spaces, only in the pattern that comes right after it.

    Example: to_char(now(), 'FMDD.FMMM.YYYY')

  • MS / US / OF

    MS shows milliseconds, US microseconds, and OF the offset from UTC.

    Example: to_char(now(), 'HH24:MI:SS.MS OF')

  • Day / DY / D / ID

    Day shows the full name of the day, padded with spaces to nine characters, and DY its abbreviation in uppercase. D shows the day number from 1 (Sunday) to 7 (Saturday), and ID the ISO 8601 day number, from 1 (Monday) to 7 (Sunday).

    Example: to_char(now(), 'FMDay DD.MM.YYYY')

  • to_timestamp('29.11.2026', 'DD.MM.YYYY')

    Converts a string to a timestamp with time zone value according to a format. A string without a time zone is interpreted in the time zone of the connection.

  • to_timestamp(1700000000)

    Converts a Unix timestamp in seconds to a timestamp with time zone value.

    Example: to_timestamp(1284352323) = 2010-09-13 04:32:03+00

  • extract(epoch from now())

    Returns the number of seconds since January 1, 1970, UTC, including fractions of a second.

  • SET TIME ZONE 'Asia/Jerusalem';

    Sets the time zone of the connection. timestamptz values are stored in UTC and displayed according to this setting. A full zone name includes the daylight saving time rules, while an abbreviation such as EST represents a fixed offset.

    Example: SHOW timezone;

  • now() AT TIME ZONE 'Asia/Jerusalem'

    Shows a timestamptz value as it appears in the specified time zone, without changing the setting of the connection. The result is a value without a time zone.

Dates in JavaScript

  • new Date().toISOString()

    Returns the date in ISO 8601 format, always in UTC with Z and with three digits of milliseconds. An invalid date throws a RangeError.

    Example: new Date(0).toISOString() = 1970-01-01T00:00:00.000Z

  • Date.now()

    Returns the current timestamp in milliseconds. For a timestamp in seconds, as in PHP and MySQL, divide by 1000 and round down.

    Example: Math.floor(Date.now() / 1000)

  • new Date(1700000000 * 1000)

    The Date constructor takes a timestamp in milliseconds, so multiply a timestamp in seconds by 1000.

  • new Intl.DateTimeFormat('he-IL', { timeZone: 'Asia/Jerusalem', dateStyle: 'short', timeStyle: 'short' }).format(date)

    Displays a date and time in the local format of the Hebrew (Israel) locale, in the specified time zone rather than the time zone of the browser. dateStyle and timeStyle take full, long, medium, or short.

  • { year: 'numeric', month: '2-digit', day: '2-digit' }

    Options for choosing each part of the date separately. They can't be combined with dateStyle or timeStyle. The hourCycle: 'h23' option sets a 24-hour clock.

    Example: new Intl.DateTimeFormat('he-IL', { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' })

  • date.toLocaleString('he-IL', { timeZone: 'Asia/Jerusalem' })

    A shorthand for Intl.DateTimeFormat. The output can vary between browsers and include bidirectional control characters, so don't compare it to a fixed string or parse it. To format many dates, create one Intl.DateTimeFormat object and reuse it.

Python date formats

  • datetime.now(timezone.utc)

    The current date and time in UTC, as an object that includes a time zone. The utcnow() function is deprecated, and the documentation recommends using now() with UTC instead.

    Example: from datetime import datetime, timezone

  • dt.strftime('%Y-%m-%d %H:%M:%S')

    In Python, the minutes are %M and the month is %m. %H is the hour on a 24-hour clock and %I on a 12-hour clock, and %f shows microseconds. %F and %T are shorthand for %Y-%m-%d and %H:%M:%S.

    Example: dt.strftime('%F %T')

  • dt.strftime('%d.%m.%Y')

    A date in day, month, year order. %A shows the name of the day of the week and %a its abbreviation, according to the locale settings of the environment.

    Example: dt.strftime('%A %d.%m.%Y')

  • %z / %:z / %Z

    %z shows the offset from UTC without a colon, %:z with a colon, and %Z the time zone name. For an object without a time zone, all three return an empty string.

    Example: +0200 | +02:00 | UTC

  • dt.isoformat()

    A date and time in ISO 8601 format. The timespec parameter sets the precision, for example 'seconds' or 'milliseconds'.

    Example: 2019-05-18T15:17:00+00:00

  • datetime.fromisoformat('2026-11-29T14:30:00Z')

    Parses a string in ISO 8601 format. In recent versions, the function also accepts the Z suffix and returns an object in UTC.

  • datetime.strptime('29.11.2026', '%d.%m.%Y')

    Converts a string to a date according to a format, with the same codes as strftime().

  • datetime.fromtimestamp(1700000000, timezone.utc)

    Converts a Unix timestamp to a date and time in UTC. Without the second argument, the result is local time, in an object without a time zone.

  • dt.astimezone(ZoneInfo('Asia/Jerusalem'))

    Converts a date to a time zone by its name in the IANA database. The zoneinfo module is part of the standard library.

    Example: from zoneinfo import ZoneInfo

The date command in Linux

  • date '+%F %T'

    %F is the date in YYYY-MM-DD format and %T the time in HH:MM:SS format.

    Example: 2026-11-29 14:30:00

  • date +%d.%m.%Y

    A date in day, month, year order. In a crontab line, the % character marks a new line, so put a backslash before it.

    Example: date +\%d.\%m.\%Y

  • date -u

    Shows the date and time in UTC.

  • date +%s

    Shows the current timestamp in seconds.

  • date -d @1700000000

    Converts a timestamp to a date and time in the time zone of the server. With -u, the result is in UTC.

    Example: date -u -d @1700000000

  • TZ=Asia/Jerusalem date

    Shows the time in another time zone for this command only, without changing the server settings. The tzselect command helps you find the right zone name.

    Example: TZ=UTC date

  • date -Iseconds

    A date and time in ISO 8601 format with the offset from UTC. The -I option alone shows only the date, and there are also hours, minutes, and ns.

    Example: 2006-08-14T02:34:56-06:00

  • date -R

    A date in RFC 5322 format, as in the Date header of an email message.

    Example: Mon, 14 Aug 2006 02:34:56 +0000

  • date --rfc-3339=seconds

    A date and time in RFC 3339 format, with a space between the date and the time. The ns value adds nanoseconds.

    Example: 2006-08-14 02:34:56-06:00

  • date '+%z %:z %Z'

    %z shows the offset from UTC without a colon, %:z with a colon, and %Z the time zone abbreviation.

    Example: -0400 -04:00 EDT

Time zones

  • UTC

    A uniform time standard with no daylight saving time, used as the reference point for all time zones. Store times in the database and in log files in UTC, and convert them to local time only when you display them to the user.

  • Asia/Jerusalem

    A time zone name from the IANA time zone database. The database keeps the history of local time and the daylight saving time rules, and it's updated when countries change them. A zone name is better than a fixed offset, because it calculates the correct offset for each date.

    Example: Europe/London | America/New_York

  • +02:00 / +03:00

    In the Asia/Jerusalem zone, the offset from UTC changes between +02:00 in winter and +03:00 in daylight saving time. When daylight saving time starts, one hour doesn't exist, and when it ends, one hour occurs twice. These hours need attention when you schedule tasks and calculate time differences.

  • timedatectl

    Shows the local time, the time in UTC, the time zone of the server, and whether network time synchronization is active.

  • timedatectl list-timezones | grep Asia

    Lists the available time zone names and filters them by continent.

  • sudo timedatectl set-timezone Asia/Jerusalem

    Caution: changes the time zone of the entire server, and from then on, the times in logs and scheduled tasks are based on the new time zone. You can also keep the server on UTC and set the time zone in the application.

    Example: sudo timedatectl set-timezone UTC

  • sudo timedatectl set-local-rtc 0

    Keeps the hardware clock of the server in UTC. The documentation warns that a hardware clock in local time isn't fully supported and causes problems, especially with time zone changes and daylight saving time transitions.

  • date.timezone = "Asia/Jerusalem"

    The PHP time zone in php.ini, which applies to all the date functions when the script doesn't set another zone.

Which format to choose

To store times and exchange them between systems, in APIs, JSON files, and log files, use RFC 3339 with Z or with an offset from UTC, or a Unix timestamp. HTTP headers use the IMF-fixdate format in GMT, and the Date header of an email message uses the RFC 5322 format. A local format is only for display to the user. To quickly convert between a timestamp and a date, you can use the Unix timestamp converter.

Local date format for Hebrew and Israeli locales

In Hebrew and Israeli locales, dates are usually written in day, month, year order, for example 29.11.2026 or 29/11/2026, and the time on a 24-hour clock. In the US format, a date such as 03/04/2026 is read as March 4 rather than April 3, so in files and databases, store the date in YYYY-MM-DD format and convert it to the local format only for display.

Dates in the database and the year 2038

A timestamp stored as a 32-bit integer reaches the end of its range on January 19, 2038, and in MySQL this is also the end of the range of the TIMESTAMP type. For later dates, use the DATETIME type or a 64-bit numeric column. The differences between the date types are listed on the SQL data types page, and the PHP time zone setting is covered on the php.ini directives page.

Dates on the command line and in scheduled tasks

More commands for the server clock and the time zone are collected on the Linux commands page, and you manage the clock synchronization services with systemctl commands. To build a schedule expression for a crontab line, you can use the Cron expression generator.

Did you know?

A Linux VPS gives you full root access, so you can set the time zone of the server, the database, and the application as you need.

Linux VPS plans

Date and time formats FAQ

What's the difference between ISO 8601 and RFC 3339?

ISO 8601 is the international standard for writing dates and times, and it allows many forms, such as writing without separators, durations, and week numbers. RFC 3339 is a restricted profile of the standard for use on the internet, in which most fields and characters are required, for example 2026-11-29T14:30:00Z. APIs and JSON files usually use RFC 3339, which is easier to read and parse.

How do I display a date in day, month, year order?

In PHP, use the format date('d.m.Y'), in MySQL DATE_FORMAT(created_at, '%d.%m.%Y'), in PostgreSQL to_char(now(), 'DD.MM.YYYY'), in Python strftime('%d.%m.%Y'), and on the command line date +%d.%m.%Y. In JavaScript, you can display a date in the local Hebrew (Israel) format with Intl.DateTimeFormat and the he-IL locale.

Should I store dates in the database in UTC?

Yes, this is the common and safe approach. Storing times in UTC prevents duplicates and gaps when daylight saving time starts or ends, and lets you show the same moment correctly to every user in their own time zone. Convert to local time only for display, for example with CONVERT_TZ in MySQL, with AT TIME ZONE in PostgreSQL, or with a time zone in the application.

How can I tell whether a timestamp is in seconds or milliseconds?

By the number of digits. A timestamp in seconds, such as the one that date +%s and time() return, currently has 10 digits, and a timestamp in milliseconds, such as the one that Date.now() returns in JavaScript, has 13 digits. The Unix timestamp converter detects the unit automatically.

How do I change the time zone of a Linux server?

Check the current setting with timedatectl, find the zone name with timedatectl list-timezones, and change it with sudo timedatectl set-timezone Asia/Jerusalem. The change applies to the times in logs and scheduled tasks. The PHP and database time zones are set separately, in date.timezone and time_zone.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement