date() function
The date()
function is used to format the current date and time.
time()
The time()
function returns the current Unix timestamp.
strtotime()
The strtotime()
function parses a string containing a date and returns a Unix timestamp.
date_create()
, date_format()
These functions are used to create and format a date object.
<?php
// Output: Current date formatted as "d-m-Y"
$date = date_create();
echo date_format($date, "d-m-Y");
?>
strtotime()
and date()
Combining strtotime()
and date()
to format a date from a string.
getdate()
The getdate()
function returns an associative array containing information about the current date.
strftime()
The strftime()
function formats a local time/date according to locale settings.
date_diff()
The date_diff()
function calculates the difference between two dates.
These are just a few examples of PHP date and time functions. Depending on your needs, you may find other functions like strtotime()
, date_add()
, and date_sub()
useful for more advanced date and time manipulation.
date() function
The date()
function is used to format the current date and time.
time()
The time()
function returns the current Unix timestamp.
strtotime()
The strtotime()
function parses a string containing a date and returns a Unix timestamp.
date_create()
, date_format()
These functions are used to create and format a date object.
<?php
// Output: Current date formatted as "d-m-Y"
$date = date_create();
echo date_format($date, "d-m-Y");
?>
strtotime()
and date()
Combining strtotime()
and date()
to format a date from a string.
getdate()
The getdate()
function returns an associative array containing information about the current date.
strftime()
The strftime()
function formats a local time/date according to locale settings.
date_diff()
The date_diff()
function calculates the difference between two dates.
These are just a few examples of PHP date and time functions. Depending on your needs, you may find other functions like strtotime()
, date_add()
, and date_sub()
useful for more advanced date and time manipulation.