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 ZONEallows you to switch between time zones; - to get the current date and time, you can use:
GETDATE(),CURRENT_TIMESTAMP,SYSDATETIME(),GETUTCDATE(),SYSUTCDATETIME(),SYSDATETIMEOFFSET().
- to get parts of a date and/or time, you can use the
YEAR(),MONTH(),DAY(),DATEPART(), orDATENAME()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()orCONVERT()functions.
Are you ready to practice what you've learned?
Exercise
Click to start.



