0% found this document useful (0 votes)
44 views3 pages

Date Functions

This document describes various date, time, and datetime functions available in MySQL including NOW(), CURDATE(), CURTIME(), DATE(), TIME(), YEAR(), MONTH(), DAY(), HOUR(), MINUTE(), SECOND(), DATE_ADD(), DATE_SUB(), DATE_FORMAT(), TIMESTAMPDIFF(), TIMESTAMPADD(), DAYNAME(), DAYOFWEEK(), LAST_DAY(), TIMEDIFF(), MAKEDATE(), YEARWEEK(), ADDDATE(), SUBDATE(), DATEDIFF(), TIME_FORMAT(), WEEK(), UNIX_TIMESTAMP(), FROM_UNIXTIME(), TIME_TO_SEC(), SEC_TO_TIME(), TIMEZONE(), and UTC_TIMESTAMP().

Uploaded by

sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views3 pages

Date Functions

This document describes various date, time, and datetime functions available in MySQL including NOW(), CURDATE(), CURTIME(), DATE(), TIME(), YEAR(), MONTH(), DAY(), HOUR(), MINUTE(), SECOND(), DATE_ADD(), DATE_SUB(), DATE_FORMAT(), TIMESTAMPDIFF(), TIMESTAMPADD(), DAYNAME(), DAYOFWEEK(), LAST_DAY(), TIMEDIFF(), MAKEDATE(), YEARWEEK(), ADDDATE(), SUBDATE(), DATEDIFF(), TIME_FORMAT(), WEEK(), UNIX_TIMESTAMP(), FROM_UNIXTIME(), TIME_TO_SEC(), SEC_TO_TIME(), TIMEZONE(), and UTC_TIMESTAMP().

Uploaded by

sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.NOW(): Returns the current date and time.

Example:
SELECT NOW();

2.CURDATE(): Returns the current date.

Example:

SELECT CURDATE();

3.CURTIME(): Returns the current time.

Example:
SELECT CURTIME();

4.DATE(): Extracts the date part from a datetime value.

Example:
SELECT DATE(NOW());

5.TIME(): Extracts the time part from a datetime value.

Example:
SELECT TIME(NOW());

6.YEAR(): Extracts the year from a date or datetime.


Example:
SELECT YEAR(NOW());

7.MONTH(): Extracts the month from a date or datetime.


Example:
SELECT MONTH(NOW());

8.DAY(): Extracts the day of the month from a date or datetime.


Example:
SELECT DAY(NOW());

9.HOUR(): Extracts the hour from a time or datetime.


Example:
SELECT HOUR(NOW());

10.MINUTE(): Extracts the minute from a time or datetime.


Example:
SELECT MINUTE(NOW());

11.SECOND(): Extracts the second from a time or datetime.


Example:
SELECT SECOND(NOW());

12.DATE_ADD(): Adds a specified time interval to a date or datetime.


Example:
SELECT DATE_ADD(NOW(), INTERVAL 7 DAY);

13.DATE_SUB(): Subtracts a specified time interval from a date or datetime.


Example:
SELECT DATE_SUB(NOW(), INTERVAL 2 MONTH);
These are just a few of the many date and time functions available in MySQL. You
can use these functions to manipulate, extract, and work with date and time values
in your SQL queries.
-------------------------------------------
Certainly, here are more date, month, day, year, and time-related functions in
MySQL:

1.DATE_FORMAT(): Formats a date or datetime according to a specified format.


SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s');

2.TIMESTAMPDIFF(): Returns the difference between two date or datetime expressions.


SELECT TIMESTAMPDIFF(SECOND, '2023-01-01 00:00:00', NOW());

3.TIMESTAMPADD(): Adds a specified time interval to a date or datetime expression.


SELECT TIMESTAMPADD(MINUTE, 30, NOW());
4.DAYNAME(): Returns the name of the day of the week for a date.
SELECT DAYNAME(NOW());
5.DAYOFWEEK(): Returns the day of the week as an index (1 = Sunday, 2 = Monday,
etc.) for a date.
SELECT DAYOFWEEK(NOW());

6.LAST_DAY(): Returns the last day of the month for a given date.
SELECT LAST_DAY(NOW());
7.TIMEDIFF(): Returns the time difference between two time or datetime expressions.
SELECT TIMEDIFF('14:30:00', '12:15:30');

8.MAKEDATE(): Creates a date from a year and a day number.


SELECT MAKEDATE(2023, 100);

9.YEARWEEK(): Returns the year and week number for a date.


SELECT YEARWEEK(NOW());

10.ADDDATE(): Adds a specified time interval to a date or datetime expression.


SELECT ADDDATE(NOW(), INTERVAL 5 DAY);

11.SUBDATE(): Subtracts a specified time interval from a date or datetime


expression.
SELECT SUBDATE(NOW(), INTERVAL 2 WEEK);

12.DATEDIFF(): Returns the difference in days between two date expressions.


SELECT DATEDIFF(NOW(), '2023-01-01');

13.TIME_FORMAT(): Formats a time value according to a specified format.


SELECT TIME_FORMAT(NOW(), '%H:%i:%s');

14.WEEK(): Returns the week number for a date.


SELECT WEEK(NOW());

15.UNIX_TIMESTAMP(): Returns the Unix timestamp (seconds since January 1, 1970) for
a date or datetime expression.
SELECT UNIX_TIMESTAMP(NOW());

16.FROM_UNIXTIME(): Converts a Unix timestamp to a date or datetime expression.


SELECT FROM_UNIXTIME(1609459200);

17.TIME_TO_SEC(): Converts a time value to seconds.


SELECT TIME_TO_SEC('12:15:30');
18.SEC_TO_TIME(): Converts seconds to a time value.
SELECT SEC_TO_TIME(45000);

19.TIMEZONE(): Returns the time zone of the current session.


SELECT TIMEZONE();

20.UTC_TIMESTAMP(): Returns the current UTC date and time.


SELECT UTC_TIMESTAMP();

These functions provide various ways to work with date, time, and related values in
MySQL queries.

You might also like