You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Cheat-Sheets/SQL.md
+48-6Lines changed: 48 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -558,17 +558,59 @@ SET TRANSACTION ISOLATION LEVEL READ COMMITTED; -- Example
558
558
559
559
## Date and Time Functions
560
560
561
+
561
562
*`NOW()`, `CURRENT_TIMESTAMP`: Returns the current date and time.
562
563
*`CURDATE()`, `CURRENT_DATE`: Returns the current date.
563
564
*`CURTIME()`, `CURRENT_TIME`: Returns the current time.
564
565
*`DATE(expression)`: Extracts the date part of a date or datetime expression.
565
566
*`TIME(expression)`: Extracts the time part of a time or datetime expression.
566
-
*`YEAR(date)`, `MONTH(date)`, `DAY(date)`: Extracts the year, month, or day.
567
-
*`HOUR(time)`, `MINUTE(time)`, `SECOND(time)`: Extracts the hour, minute, or second.
568
-
*`DATE_ADD(date, INTERVAL expr unit)`, `DATE_SUB(date, INTERVAL expr unit)`: Adds or subtracts a time interval.
569
-
*`DATEDIFF(date1, date2)`: Returns the difference between two dates (in days).
570
-
*`TIMESTAMPDIFF(unit, datetime1, datetime2)`: Returns the difference between two datetimes in a specified unit.
571
-
*`DATE_FORMAT(date, format)`: Formats a date.
567
+
*`YEAR(date)`, `MONTH(date)`, `DAY(date)`: Extracts the year, month, or day from a date.
568
+
*`HOUR(time)`, `MINUTE(time)`, `SECOND(time)`: Extracts the hour, minute, or second from a time.
569
+
*`EXTRACT(unit FROM datetime)`: Extracts a specific unit (e.g., `YEAR`, `MONTH`, `DAY`, `HOUR`, `MINUTE`, `SECOND`) from a date or timestamp.
570
+
*`DATE_ADD(date, INTERVAL expr unit)`, `DATE_SUB(date, INTERVAL expr unit)`: Adds or subtracts a time interval (units: `DAY`, `WEEK`, `MONTH`, `YEAR`, etc.).
571
+
*`DATEDIFF(date1, date2)`: Returns the difference between two dates (result unit varies by database, often days).
572
+
*`TIMESTAMPDIFF(unit, datetime1, datetime2)`: Returns the difference between two datetimes in a specified unit (units: `MINUTE`, `HOUR`, `SECOND`, `DAY`, `MONTH`, `YEAR`).
573
+
*`DATE_FORMAT(date, format)`: Formats a date according to the specified format string (format codes vary by database).
574
+
*`DAYOFWEEK(date)`: Returns the day of the week as a number (e.g., 1=Sunday, 2=Monday...).
575
+
*`WEEKOFYEAR(date)`: Returns the week number of the year.
576
+
*`QUARTER(date)`: Returns the quarter of the year (1-4).
577
+
*`WEEK(date)`: Returns the week number (behavior can vary based on mode/database).
0 commit comments