Introduction
Dealing with dates
Working with time data
Date and time date
Extracting dates and times
Doing arithmetic with dates
Converting date and time data
Current date and time data
Building date and time data from parts
Summary and review
48. Summary

Instruction

Fantastic job! It's time to review what we know about date and time in SQL Server:

  • SQL uses dates ('2010-01-01'), times ('13:00:00'), and precise datetimes ('2010-01-01 13:00:00');
  • you can compare the above types using BETWEEN;
  • you can specify their order with ORDER BY;
  • the function AT TIME ZONE allows you to switch between time zones;
  • to get the current date and time, you can use:
    • GETDATE(),
    • CURRENT_TIMESTAMP,
    • SYSDATETIME(),
    • GETUTCDATE(),
    • SYSUTCDATETIME(),
    • SYSDATETIMEOFFSET().
    These functions have different levels of precision;
  • to get parts of a date and/or time, you can use the YEAR(), MONTH(), DAY(), DATEPART(), or DATENAME() functions;
  • to add a specific number of days, months, years, etc. to your date you can use DATEADD() function;
  • to get the difference between two dates you can use the DATEDIFF() function;
  • the EOMONTH() function returns the last day of the month the given date belongs to;
  • you can convert date and time values to other data types by using the CAST() or CONVERT() functions.

Are you ready to practice what you've learned?

Exercise

Click Next exercise to start.