Here’s an example of how you can use a variable in the real world: show the current date on your website.
<?php $today = date("F j, Y"); echo "$today"; ?>
This example sets the date command as a variable called “$today”, and uses echo to display it on the screen.
More about the “DATE” command - it is very versatile and flexible - see the guide below to use it to it’s potential!
The DATE command
Expanding on the above example, here are the options for DATE and TIME display:
Time:
a: am or pm
A: AM or PM
g: Hour without leading zeroes (1-12)
G: Hour in military time without leading zeroes (0-23)
h: Hour with leading zeroes (01-12)
H: Hour in military time with leading zeroes (00-23)
i: Minute with leading zeroes (00-59)
s: Seconds with leading zeroes (00-59)
Days:
d: Day of the month with leading zeroes (01-31)
j: Day of the month without leading zeroes (1-31)
D: Day of the week abbreviations (Sun – Sat)
I: Day of the week (Sunday – Saturday)
w: Day of the week without leading zeroes (0-6)
z: Day of the year without leading zeroes (1-365)
Months:
m: Month of the year with leading zeroes (01-12)
n: Month of the year without leading zeroes (1-12)
M: Month abbreviations (Jan – Dec)
F: Month names (January – December)
t: Number of days in the month (28-31)
Years:
L: Displays 1 if it is a leap year, 0 if not
Y: Year in 4-digit format (2006)
y: Year in 2-digit format (06)
Other Date Formats:
r: Full date, including timestamp and timezone offset (O)
U: Number of seconds since the Unix Epoch (Jan. 1, 1970)
O: Offset difference from Greenwich Meridian Time (GMT). 100 = 1 hour, -100 = -1 hour
0 Comments
Leave a Reply. |
David Rentson
If this free PHP and MYSQL Tutorial is helpful for you... Great! Archives
October 2008
Categories
All
|