SQL Server DATETIME, DATE and TIME data types | Manipulating Dates, times and Strings | SQL basics

preview_player
Показать описание
SQL Server DATETIME, DATE and TIME data types are essential to know before attempting pretty much any query involving time periods in data. Knowing how to convert date and time types to and from string values can prove problematic if you arent familiar with how SQL server defines and parses dates.

In this video I'll show you each DATE data type and describe its basic form, how to convert dates to and from strings, and the issues you might have trying to query against date values due to the locale settings on your SQL server.

I'll also go through how to manipulate dates and times by separating out date parts using the DATEPART and DATENAME functions, retrieving the current date using either GETDATE() or CURRENT_TIMESTAMP functions, adding, subtracting and finding the difference between dates using the DATEADD and DATEDIFF functions, and finally how to use what you've learned to create functions that show the first and last dates of the week, month or quarter.



Useful links relating to this video :

An excellent overview of the main SQL Server date and time functions all in one place.

A great article on rounding dates to get different set periods such as the first date in a month or a quarter etc.

The link to the Microsoft documentation on the CAST and CONVERT functions, showing all the available styles.

Microsoft documentation detailing the limitations of each date data type.

Documentation for the FORMAT function, showing the different types of date and time formatting codes.

A further look into how SQL server stores dates and times, and a few important things to remember when working with dates and times

Video Chapters

00:00 Intro
00:29 Date and Time Datatypes
04:13 How Dates are stored in the database
06:05 Converting a date to a string
09:17 Converting a string to a date
10:59 Separating dates from times
12:22 Getting the current date and time
13:11 Getting parts of dates and times with DATEPART and DATENAME
14:10 Finding the difference between two dates with DATEDIFF
14:59 Adding and subtracting periods to a date with DATEADD
15:18 Get first / last day of the week / month / quarter
19:01 Outro
Рекомендации по теме
Комментарии
Автор

This was outstandingly well done. Pure gold!

ndiayej
Автор

Thank you for the helpful information. You made it understandable.

heribertobarrios
Автор

bro you should make more videos on SQL

yuvraj
Автор

Which data type I should use in sql plus if want to store only time

Prashant_parghi
Автор

There are 658 days. How to convert year months and days in MySQL query

advancewebdevelopment
Автор

to be honest i didn't understand a thing so far and i'm 5 minutes in...

MM-owmd
Автор

how do i select all records that have an event datetime witin 1 hour before, for example mysql select all that time_diff less than 1 hour from datetime? its for a reminder email i want to make on a cronjob can you help with this sql query?

JNET_Reloaded
welcome to shbcf.ru