Date Functions

The date functions allow you to perform functions on date. Some methods require additional parameters.

Create Date

It creates a new current date in the format 'Y-m-d H:i:s'. This format is used to store date directly in the database.

Format Date

It returns the date formatted according to a given format. You can use format characters as parameter like: d M, Y

Date Format Characters

  • d - Day of the month (2 digits, zero-padded) 01 to 31
  • D - Day of the week (3 letters) Mon, Tue
  • j - Day of the month (no leading zero) 1 to 31
  • l - (lowercase L) - Full day name like Monday
  • N - ISO day of the week (1 = Monday, 7 = Sunday) 1 to 7
  • S - English ordinal suffix for the day like st, nd, rd, th
  • w - Numeric day of the week (0 = Sunday) 0 to 6
  • z - Day of the year (starting from 0) 0 to 365

Month Format Characters

  • F - Full month name like January
  • m - Numeric month (2 digits) 01 to 12
  • M - Short month name (3 letters) Jan, Feb
  • n - Numeric month (no leading zero) 1 to 12
  • t - Number of days in the month: 28, 30, 31

Year Format Characters

  • Y - Full year (4 digits) 2025
  • y - Short year (2 digits) 25
  • L - Leap year? (1 if yes, 0 if no) 1 or 0

Time Format Characters

  • a - am/pm (lowercase) am, pm
  • A - AM/PM (uppercase) AM, PM
  • g - 12-hour (no leading zero) 1 to 12
  • G - 24-hour (no leading zero) 0 to 23
  • h - 12-hour (2 digits) 01 to 12
  • H - 24-hour (2 digits) 00 to 23
  • i - Minutes (2 digits) 00 to 59
  • s - Seconds (2 digits) 00 to 59
  • u - Microseconds (6 digits) 654321

Full Formats

  • c - ISO 8601 date like 2025-09-05T14:30:00+00:00
  • r - RFC 2822 date like Fri, 05 Sep 2025 14:30:00 +0000
  • U - Unix timestamp like 1757063400

Modify Date

It modifies the date using a relative string. You can add parameter like:

  • +3 days
  • -1 week
  • +2 months
  • next Monday
  • last Friday

Adding or Subtracting Intervals

It adds or subtracts interval. You can add the interval like: P5D

Basic Syntax: P[n]Y[n]M[n]DT[n]H[n]M[n]S

  • P = Period (starts the interval)
  • T = Time (separates date and time parts)

To ISO 8601

ISO 8601 is an international standard for date and time representation.

Format structure: YYYY-MM-DDTHH:MM:SS±HH:MM

Example: 2025-09-05T14:30:00+02:00

To RFC 822

RFC 822 is used for formatting date and time, in email headers and feeds.

Format Structure: D, d M Y H:i:s O

Example: Fri, 05 Sep 2025 14:30:00 +0200

To Unix

The Unix timestamp is the number of seconds since January 1, 1970 00:00:00 UTC (the Unix epoch).

Timestamps are easy to compare (just numbers) and store (integers). They are Independent of time zones (always UTC).

To Sql

It provides the date that is compatible to be stored in the database. For example, Y-m-d H:i:s for SQL.