JavaScript Tutorial

PHP Date & Time Functions

Date and time functions in PHP help in retrieving date and time from the server and then format the result by various methods given in PHP. The output of these functions depends upon the locale settings of the server.

Here is the list of php date and time functions

Method Description

checkdate

It is used for the validation of Gregorian date.

date_add

alias of DateTime::add()

It is used to add a given number of days, months, years, hours, minutes, and seconds to a date.

date_create_from_format

alias of DateTime::createFromFormat

It returns a new DateTime object formatted according to the specified format.

date_create

alias of DateTime::__construct()

It returns a new DateTime object.

date_date_set

alias of DateTime::setDate

It is used to set a new date.

date_default_timezone_get

It returns the default timezone used by all date/time functions.

date_default_timezone_set

It sets the default timezone used by all date/time functions

date_diff

alias of DateTime::diff

date_format

alias of DateTime::format

It returns a date formatted according to the specified format.

date_get_last_errors

alias of DateTime::getLastErrors()

It returns the warnings/errors

date_interval_create_from_date_string

alias of DateInterval::createFromDateString()

It sets up a DateInterval from the relative parts of the string.

date_interval_format

alias of DateInterval::format()

It is used to format the interval.

date_isodate_set

alias of DateTime::setISODate()

It returns a date according to the ISO 8601 standard using weeks and day offsets

date_modify

alias of DateTime::modify

It modifies the timestamp.

date_offset_get

alias of DateTime::getOffset

It returns the timezone offset.

date_parse_from_format

It returns information about given date formatted according to the specified format

date_parse

It returns an associative array having information about a given date.

date_sub

alias of DateTime::sub()

It is used to subtract a given number of days, months, years, hours, minutes, and seconds from a date.

date_sun_info

It returns an array containing information about sunset/sunrise and twilight begin/end

date_sunrise

It returns time of sunset for a given day and location.

date_sunset

It returns time of sunset for a given day and location.

date_time_set

alias of DateTime::setTime

It is used to set the time.

date_timestamp_get

alias of DateTime::getTimestamp

It returns the Unix timestamp

date_timestamp_set

alias of DateTime::setTimestamp

It helps to sets the date and time based upon a Unix timestamp.

date_timezone_get

alias of DateTime::getTimezone()

It returns the timezone of the DateTime object.

date_timezone_set

alias of DateTime::setTimezone()

It is used to set the timezone for DateTime Object.

date

It formats a local date/time and returns a string

getdate

Returns an associative array having date information of the timestamp or the current local time if timestamp is omitted or NULL.

gettimeofday

It returns the current time.

gmdate

It formats a GMT/UTC date/time

gmmktime

It returns the Unix timestamp for a GMT date.

gmstrftime

It formats GMT/UTC date and time as per locale settings

idate

It formats a locate time/date as integer.

localtime

It returns the local time

microtime

It returns current unix timestamp with microseconds.

mktime

It returns the Unix timestamp for a date

strftime

It formats a local time/date as per locale settings.

strptime

It parses a time/date generated with strftime().

strtotime

Parsing of any English datetime description into Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).

It carefully handle dates in the m/d/y or d-m-y formats.

  • if the separator is a slash (/), then the American m/d/y is considered.
  • If the separator is a dash (-) or a dot (.), then the European d-m-y format is considered.
    • To avoid potential errors, use YYYY-MM-DD dates or date_create_from_format().

time

It returns the current time in number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

timezone_abbreviations_list

It returns an associative array with DST, offset and timezone name.

Alias of DateTimeZone::listAbbreviations

timezone_identifiers_list

It returns an array having all timezone identifiers.

Alias of DateTimeZone::listIdentifiers

timezone_location_get

It returns the information about location of the given timezone.

timezone_name_from_ abbr

It returns the timezone name from abbreviation

timezone_name_get

It returns the name of timezone.

Alias of DateTimeZone::getName

timezone_offset_get

It returns the timezone offset from GMT.

Alias of DateTimeZone::getOffset

timezone_open

It creates a new DateTimeZone Object.

Alias of DateTimeZone::__construct

timezone_transitions_get

It returns all the transitions of timezone.

Alias of DateTimeZone::getTransitions and it can be called in two different ways.

timezone_version_get

It returns the version of timezonedb.

 

Go back to Previous Course