You get a bonus - 1 coin for daily activity. Now you have 1 coin

Work with date and time PHP

Lecture



Functions for working with date and time.

These functions allow you to get the current time on the server on which the script is executed. In addition to receiving, time can be represented in various formats, calculate the difference between two points in time and even find out the time of sunrise in a particular area on a given day!

Let's see the main of these functions.

bool checkdate (int $ month, int $ day, int $ year)
Returns TRUE if the date given by the arguments is correct; otherwise, it returns FALSE. The date is considered correct if:
year in the range from 1 to 32767 inclusive
month ranging from 1 to 12 inclusive
day is a valid day number for the month specified by the month argument, taking into account that year can specify a leap year.

array date_parse (string $ date)
Returns an associative array with information about the date $ date. The array contains year, day, month, hours, minutes, seconds, and something else interesting.

array date_sun_info (int $ time, float $ latitude, float $ longitude)
Returns an array with the time of sunrise, sunset, daylight, and so on.
Arguments is a timestamp that can be, for example, obtained from a string using the datetotime ($ str) function. Or function time () - the current time.

string date (string $ format [, int $ timestamp])
Returns the time formatted according to the format argument using the timestamp specified by the timestamp argument or the current system time if the timestamp is not set.
Format is a string containing formatting characters. And ordinary characters too. Normal are displayed as is, and the formatting characters are replaced with the corresponding values:

Character in the format string Description Sample return value
a Ante meridiem or Post meridiem in lower case am or pm
A Ante meridiem or Post meridiem uppercase AM or PM
B Swatch Internet Standard Time From 000 to 999
c Date in ISO 8601 format (added in PHP 5) 2004-02-12T15: 19: 21 + 00: 00
d Day of the month, 2 digits with leading zeros from 01 to 31
D Abbreviated name of the day of the week, 3 characters Mon to Sun
F Full name of the month, for example, January or March from January to December
g Clock in 12-hour format without leading zeros 1 to 12
G 24-hour clock with no leading zeros From 0 to 23
h Clock in 12-hour format with leading zeros 01 to 12
H Hours in 24-hour format with leading zeros 00 to 23
i Minutes with leading zeros 00 to 59
I (capital i) Sign of summer time 1 if the date is daylight, otherwise 0 otherwise.
j Day of the month without leading zeros 1 to 31
l (lower case 'L') Full name of the day of the week From Sunday to Saturday
L Leap Year Sign 1 if the year is a leap year, otherwise 0 .
m Month ordinal with leading zeros 01 to 12
M Abbreviated name of the month, 3 characters From Jan to Dec
n Order number of the month without leading zeros 1 to 12
O The difference with GMT time in hours For example: +0200
r Date in RFC 2822 format For example: Thu, 21 Dec 2000 16:01:07 +0200
s Seconds with leading zeros 00 to 59
S English suffix of the ordinal day of the month, 2 characters st , nd , rd or th . Used with j
t Number of days in the month 28 to 31
T Server time zone Examples: EST , MDT ...
U The number of seconds elapsed since the beginning of the Unix Epoch (The Unix Epoch, January 1, 1970, 00:00:00 GMT) See also time ()
w The ordinal number of the day of the week From 0 (Sunday) to 6 (Saturday)
W The ordinal number of the week of the year according to ISO-8601, the first day of the week - Monday (added in PHP 4.1.0) For example: 42 (42nd week of the year)
Y Order number of the year, 4 digits Examples: 1999 , 2003
y Year number, 2 digits Examples: 99 , 03
z The ordinal number of the day in the year (numbering from 0) From 0 to 365
Z Time zone offset in seconds. For time zones west of UTC, this is a negative number, and east of UTC is a positive number. From -43200 to 43200

int time (void)
Returns the number of seconds elapsed since the beginning of the Unix Epoch (The Unix Epoch, January 1, 1970, 00:00:00 GMT) to the current time.


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Running server side scripts using PHP as an example (LAMP)

Terms: Running server side scripts using PHP as an example (LAMP)