Returns the current timestamp as an INTEGER.
> select NOW();
mysql+------------+
| NOW() |+------------+
1615788407 |
| +------------+
1 row in set (0.00 sec)
Returns the current time in the local timezone in hh:ii:ss
format.
> select CURTIME();
mysql+-----------+
| CURTIME() |+-----------+
07:06:30 |
| +-----------+
1 row in set (0.00 sec)
Returns the current time in UTC timezone in hh:ii:ss
format.
> select UTC_TIME();
mysql+------------+
| UTC_TIME() |+------------+
06:06:18 |
| +------------+
1 row in set (0.00 sec)
Returns the current time in UTC timezone in YYYY-MM-DD hh:ii:ss
format.
> select UTC_TIMESTAMP();
mysql+---------------------+
| UTC_TIMESTAMP() |+---------------------+
2021-03-15 06:06:03 |
| +---------------------+
1 row in set (0.00 sec)
Returns the integer second (in 0..59 range) from a timestamp argument, according to the current timezone.
> select second(now());
mysql+---------------+
second(now()) |
| +---------------+
52 |
| +---------------+
1 row in set (0.00 sec)
Returns the integer minute (in 0..59 range) from a timestamp argument, according to the current timezone.
> select minute(now());
mysql+---------------+
minute(now()) |
| +---------------+
5 |
| +---------------+
1 row in set (0.00 sec)
Returns the integer hour (in 0..23 range) from a timestamp argument, according to the current timezone.
> select hour(now());
mysql+-------------+
hour(now()) |
| +-------------+
7 |
| +-------------+
1 row in set (0.00 sec)
Returns the integer day of the month (in 1..31 range) from a timestamp argument, according to the current timezone.
> select day(now());
mysql+------------+
day(now()) |
| +------------+
15 |
| +------------+
1 row in set (0.00 sec)
Returns the integer month (in 1..12 range) from a timestamp argument, according to the current timezone.
> select month(now());
mysql+--------------+
month(now()) |
| +--------------+
3 |
| +--------------+
1 row in set (0.00 sec)
Returns the integer year (in 1969..2038 range) from a timestamp argument, according to the current timezone.
> select year(now());
mysql+-------------+
year(now()) |
| +-------------+
2021 |
| +-------------+
1 row in set (0.00 sec)
Returns the integer year and month code (in 196912..203801 range) from a timestamp argument, according to the current timezone.
> select yearmonth(now());
mysql+------------------+
| yearmonth(now()) |+------------------+
202103 |
| +------------------+
1 row in set (0.00 sec)
Returns the integer year, month, and date code (ranging from 19691231 to 20380119) based on the current timezone.
> select yearmonthday(now());
mysql+---------------------+
| yearmonthday(now()) |+---------------------+
20210315 |
| +---------------------+
1 row in set (0.00 sec)
Calculates the difference between two timestamps in the format hh:ii:ss
.
> select timediff(1615787586, 1613787583);
mysql+----------------------------------+
1615787586, 1613787583) |
| timediff(+----------------------------------+
555:33:23 |
| +----------------------------------+
1 row in set (0.00 sec)
Returns a formatted string based on the provided date and format arguments. The format argument uses the same specifiers as the strftime function. For convenience, here are some common format specifiers:
%Y
- Four-digit year%m
- Two-digit month (01-12)%d
- Two-digit day of the month (01-31)%H
- Two-digit hour (00-23)%M
- Two-digit minute (00-59)%S
- Two-digit second (00-59)%T
- Time in 24-hour format (%H:%M:%S
)Example usage:
> SELECT DATE_FORMAT(NOW(), 'year %Y and time %T');
mysql+------------------------------------------+
'year %Y and time %T') |
| DATE_FORMAT(NOW(), +------------------------------------------+
year 2023 and time 11:54:52 |
| +------------------------------------------+
1 row in set (0.00 sec)
This example formats the current date and time, displaying the four-digit year and the time in 24-hour format.