Webmaster

References : PHP 4.0


Time and date

PHP date and time functions return values as a UNIX timestamp, i.e. the number of seconds that have elapsed since 1st January 1970. Once you know this, nothing prevents you from handling time as you want.

checkdate(month, day, year) | date(format, timestamp) | getdate(timestamp) | gmdate(format, timestamp) | gmmktime(hour, minute, second, month, day, year) | microtime() | mktime(hour, minute, second, month, day, year) | time()

checkdate(month, day, year)
The function returns TRUE (1) if the date passed as the argument is valid, otherwise FALSE (0).
 
Example<?
  checkdate(6,20,2001)
?>
 
 Top
date(format, timestamp)
Returns a date string using the format and timestamp given as arguments. If no second argument is passed to the function, it holds the system's current date and time. Here are the formatting codes available for the format string:
 
Code Description
 
a am or pm.
 
A AM or PM.
 
d Day of the month (2 digits, with 0).
 
D Day of the week (3 letters).
 
F Month.
 
h Hour in 12-hour format (with 0).
 
H Hour in 24-hour format (with 0)
 
I "1" if Daylight Saving Time, otherwise "0".
 
j Day of the month (without 0)
 
l Day of the week.
 
m Number of the month (with 0).
 
M Abbreviated name of the month.
 
S English ordinal suffix (st, nd, rd, th).
 
U Number of seconds since the Unix Epoch.
 
y Year (2 digits).
 
Y Year (4 digits).
 
z Day of the year.
 
 
Example: <?
  print(date("H:I"));
?>
 
 Top
getdate(timestamp)
Returns an associative array containing the date and time of the timestamp given, or of the current system's date and time if the timestamp is omitted. Here are the various pieces of information obtained with their corresponding keys:
 
Key element Description
 
hours Hour in 24-hour format.
 
mday Day of the month.
 
minutes Minutes.
 
mon Month shown as a number.
 
month Name of month.
 
seconds Seconds.
 
wsay Day of the week shown as a digit.
 
weekday Day of the week.
 
yday Day of the year (shown as a number).
 
year Year.
 
0 Length in seconds since June the 1st 1970.
 
 
Example: <?
  getdate(time());
?>
 
 Top
gmdate(format, timestamp)
Similar to the date function, except that the date and time returned is in Greenwich Mean Time format.
 
Example<?
  gmdate("H:I");
?>
 
 Top
gmmktime(hour, minute, second, month, day, year)
Similar to the mktime function, except that it follows the Greenwich Mean Time setting and not the locale settings of the server.
 
Example<?
  gmmktime(0, 0, 0, 1, 1, 1970);
?>
 
 Top
microtime()
Returns a string made up of two numbers calculated from the system's clock. The first gives the system time in microseconds, and the second the number of seconds that have elapsed since the Unix Epoch, i.e. 1st January 1970.
 
Example<?
  microtime();
?>
 
 Top
mktime(hour, minute, second, month, day, year)
Returns a Unix timestamp, i.e. the number of seconds that have elapsed since the Unix Epoch (1st January 1970), from a date given as the argument. As with most date and time functions, the arguments are optional, and the omitted ones are replaced by the current system values.
 
Example<?
  $now = date("h");

    mktime($now +40);
?>
 
 Top
time()
Returns the number of seconds that have elapsed between the Unix Epoch (1st January 1970) and the system's current time.
 
Example<?
  $now = time();
?>
 
 Top