🗓️ 19042024 1430
📎 #sql #backend
sql_date_functions_cheatsheet
SELECT NOW();
Current date and time.
SELECT CURDATE();
Current Date
SELECT DATE_ADD(NOW(), INTERVAL 7 DAY);
Adds a specified time interval to a date.
SELECT DATE_SUB(NOW(), INTERVAL 7 DAY);
DATE_SUB(): Subtracts a specified time interval from a date.
SELECT DATEDIFF(CURDATE(), '2024-04-01');
Returns the number of days between two dates.
SELECT DAY(NOW()), MONTH(NOW()), YEAR(NOW());
Extract the day, month, and year from a date.
SELECT DAYOFWEEK(NOW());
Returns the weekday index for a date.
SELECT DAYOFYEAR(NOW());
Returns the day of the year for a date.
SELECT LAST_DAY(NOW());
Returns the last day of the month for a given date.
SELECT STR_TO_DATE('April 19, 2024', '%M %d, %Y');
Converts a string into a date.
SELECT DATE_FORMAT(NOW(), '%W, %M %d, %Y');
Format a date value.
References
- Chat Gee Pee Tee