Contents

PHP tutorials

Introduction

Syntax

Variables

Data Types

Operators

echo

If/Else

Loops

chmod()

mail()

date()

phpinfo()

 

 

Date() Function

The PHP date() function formats a timestamp to a more readable date and time. Most UNIX systems store the current time and date as a 32-bit integer containing the number of seconds since January 1, 1970 at 00:00 GMT. This is also known as the UNIX Timestamp or UNIX Epoch. This measurement is a widely used standard that PHP has chosen to utilize.

 

Syntax

date( format, timestamp)

Parameter format is required and specifies the format of the timestamp.Parameter timestamp is optional and specifies a timestamp. By default is the current date and time.

 

Examples:

<?php

echo date("Y.m.d")."<br />";
echo date("Y-m-d")."<br />";
echo date("Y/m/d")."<br />";
echo "<br />";

echo date("d.m.Y")."<br />";
echo date("d.m.y")."<br />";
echo "<br />";

echo date("l, d M Y A H:i:s");

?>

 

 

The following characters are recognized in the format parameter string

Day:

d: Day of the month, 2 digits with leading zeros

D: A textual representation of a day, three letters

j: Day of the month without leading zeros

l (lowercase 'L'): A full textual representation of the day of the week

N: ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)

S: English ordinal suffix for the day of the month, 2 characters

w: Numeric representation of the day of the week

z: The day of the year (starting from 0)

Week:

W: ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)

Month:

F: A full textual representation of a month, such as January or March

m: Numeric representation of a month, with leading zeros

M: A short textual representation of a month, three letters

n: Numeric representation of a month, without leading zeros

t: Number of days in the given month

Year:

L: Whether it's a leap year

o: ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)

Y: A full numeric representation of a year, 4 digits

y: A two digit representation of a year

Time:

a: Lowercase Ante meridiem and Post meridiem

A: Uppercase Ante meridiem and Post meridiem

B: Swatch Internet time

g: 12-hour format of an hour without leading zeros

G: 24-hour format of an hour without leading zeros

h: 12-hour format of an hour with leading zeros

H: 24-hour format of an hour with leading zeros

i: Minutes with leading zeros

s: Seconds, with leading zeros

u: Milliseconds (added in PHP 5.2.2)

Timezone:

e: Timezone identifier (added in PHP 5.1.0)

I (capital i): Whether or not the date is in daylight saving time

O: Difference to Greenwich time (GMT) in hours

P: Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)

T: Timezone abbreviation

Z: Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.

Full Date/Time:

c: ISO 8601 date (added in PHP 5)

r: » RFC 2822 formatted date

U: Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)