The function date()
You get the Date and Time in PHP by using the date() function. I will explain later how to use this feature. PHP sets the date and time by using letters. An overview of the most common:
This is how you show the time in PHP:
You will then see the time in hours:minutes:seconds
This is how you show the date in PHP:
Now we see this example: Today is Tuesday, 21 June 2011
The function mktime()
This example uses the mktime function to create a timestamp for tomorrow. To go one day in the future we simply add one to the day argument of mktime. For your future reference, we have the arguments of mktime.
Note: These arguments are all optional. If you do not supply any arguments the current time will be used to create the timestamp.
mktime(hour, minute, second, month, day, year, daylight savings time)
Notice that we used one letter at a time with the function date to get the month, day and year. For example the date("m") will return the month's number 01-12.
You get the Date and Time in PHP by using the date() function. I will explain later how to use this feature. PHP sets the date and time by using letters. An overview of the most common:
Code:
a - am or pm (lower case).
A - AM or PM (in capitals).
d - Day of the month with leading zero.
D - Day of the week with three three-letter abbreviation in English.
F - Name of the month in English
h - Hour 1 to 12, with zero.
H - Hour of 00 to 23, with zero.
g - Time from 1 to 12, without leading zeros.
G - Hours of 0-23, no leading zero.
i - Minutes of 00-59, no leading zero.
j - Day of the month from 1 to 31, without leading zeros.
l - (lowercase L) Weekday (English), Mondag through Friday.
L - Boolean leap year indicator. 0 is not a leap, 1 is a leap year.
m - Month of 1 to 12, with zero.
n - Month of 1 to 12, without leading zeros.
M - Monthly (English), three letter abbreviation, January until December
s - Seconds 00 to 59.
S - English suffix, two letters, such as th and nd. The number 2 will be 2nd.
t - Number of days in the given Mon
U - Number of days since the base name, 1 January 1970 for Unix systems.
w - Weekday, from 0 (Sunday) and to 6 (Saturday).
Y - Year in four characters, eg 1999.
y - Year in two digits, eg 99.
z - Day of the year, from 0 to 365This is how you show the time in PHP:
PHP Code:
<?php
$time = date("H:i:s");
echo "$time";?>You will then see the time in hours:minutes:seconds
This is how you show the date in PHP:
PHP Code:
<?php
$date = date("l, j F Y");
echo "Today it is $date";?>Now we see this example: Today is Tuesday, 21 June 2011
The function mktime()
This example uses the mktime function to create a timestamp for tomorrow. To go one day in the future we simply add one to the day argument of mktime. For your future reference, we have the arguments of mktime.
Note: These arguments are all optional. If you do not supply any arguments the current time will be used to create the timestamp.
mktime(hour, minute, second, month, day, year, daylight savings time)
PHP Code:
<?php
$tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));
echo "Tomorrow is ".date("m/d/y", $tomorrow); ?>Notice that we used one letter at a time with the function date to get the month, day and year. For example the date("m") will return the month's number 01-12.


7:32 AM
Unknown
Posted in: 
0 comments:
Post a Comment