PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Date and Time
Your Ad Here

Date and Time


Date and TimeThis tutorial will teach you how to show the date and time using PHP. To begin, start the PHP with the PHP tags.

<?PHP

?>

 Then to add in the date and time, put:

<?PHP
echo date (" ")
?>

You put the date and time functions in the (" "). A list of all of the PHP date and time functions and what they do is shown below.

Time

A = Uppercase 12hr time syntax --- eg. PM, AM
a = Lowercase 12hr time syntax --- eg. pm, am
G = Hours in 24 hour format without leading zeros --- eg. 13
g = Hours in 12 hour format without leading zeros --- eg. 3
H = Hours in 24 hour format with leading zeros --- eg. 13
h = Hours in 12 hour format with leading zeros --- eg. 03
i = Minutes eg. 32 s = Seconds eg. 45
T = Timezone setting eg. GMT, PST, EST, etc
O = GMT time difference in hours eg. +0400

Date

D = Day --- eg. Fri
d = Day --- eg. 03
F = Full Text Month --- eg. January
M = Month --- eg. Jan
m = Month --- eg. 01
S = Day of month suffix --- eg. st, nd, rd, or th.
t = Total numer of days in the month --- eg. 28, 31, etc.
U = Seconds since the UNIX epoch --- eg. 1041604168
W = Week number in year --- eg. 42 (42nd week in the year)
w = numeric representation of the day --- eg. 1 = monday, 2 = tuesday, etc.
Y = Year --- eg. 2005
y = Year --- eg. 05
z = Day of the year --- eg. 002

For example

<?PHP
echo date ("D dS F, Y  g:i:s a")
?>

That code would produce:

Fri 03rd January, 2005 3:32:45 pm

Experiment and work out what works best for you.



Author's URL: Ghost
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Date and Time"

Only registered users can write comment

No comments yet...