Date Functions
Published May 23, 2022
Contribute to Docs
PHP manipulates dates in a number of ways, using arrays, strings, Unix timestamps, or DateTime
objects. PHP provides a number of built-in functions for manipulating dates using these various data types.
Date Functions
- date()
- Creates a formatted date-time string from a local date-time.
- date_add()
- Adds a given number of days, months, years, hours, minutes or seconds to an existing date.
- date_create()
- Creates a new DateTime object from a formatted date-time string.
- date_diff()
- Takes two DateTime objects, calculates the difference, and returns a DateInterval object.
- date_format()
- Takes a DateTime object and returns a string based on its formatted value.
- date_parse()
- Accepts a date as a parameter, parses it, and returns information about the given date in the form of an array.
- date_sub()
- Subtracts a specified interval from a given date.
- getdate()
- Returns an array representing the current date or a Unix timestamp.
- time()
- Returns current time measured in seconds from the Unix Epoch.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.