Complete SQL Topics for Data Analysis
-> https://t.me/sqlspecialist/523
Lets learn about how to work with Dates and Times in SQL today:
Manipulating date and time data is a common task in SQL, and various functions are available for these operations.
- CURRENT_DATE:
SELECT CURRENT_DATE;
- DATEADD: DATEADD() function adds specific time/date interval to a date and then returns the date.
SELECT DATEADD(day, 7, order_date) AS future_date FROM orders;
- CURRENT_TIME:
SELECT CURRENT_TIME;
- DATEDIFF: DATEDIFF() function calculates the difference between two dates
SELECT DATEDIFF(hour, start_time, end_time) AS duration FROM events;
- FORMAT: Change the format of date field
SELECT FORMAT(order_date, 'MM/dd/yyyy') AS formatted_date FROM orders;
Understanding these functions is crucial for performing time-based analysis in SQL.
Share with credits: https://t.me/sqlspecialist
Hope it helps :)