Home >Backend Development >PHP Tutorial >Summary of commonly used MySQL date and time functions_PHP tutorial
Get the current date + time (date + time) 1.1 Function: now()
Related functions: current_timestamp(), localtime(), localtimestamp()
Example:
2. Get the current date (date)
Function: curdate()
Related functions: current_date(), current_date
Example:
3. Get the current time (time)
Function: curtime()
Related functions: current_time(), current_time
Examples
4. MySQL dayof…
Functions: dayofweek(), dayofmonth(), dayofyear() return the date parameters and their positions in the week, month, and year respectively.
Examples
set @dt = '2008-08-08';
select dayofweek(@dt); -- 6
select dayofmonth(@dt); -- 8
select dayofyear(@dt); -- 221
The date ‘2008-08-08′ is the 6th day of the week (1 = Sunday, 2 = Monday, …, 7 = Saturday)
The 8th day of January; the 221st day of the year