How to Use Datetime in SQL - SQL Training Online - Quick Tips Ep33

Опубликовано: 19 Октябрь 2012
на канале: Joey Blue
43,872
342

How to use a Datetime in SQL.

The datetime is actually made up of two different pieces:
1) Date
2) Time

This can be demonstrated using the SQL Cast function on a string to convert it to a datetime.

Here is some SQL for the Date portion:
select cast('20121019' as datetime)

Here is some SQL for the Time portion:
select cast('10:05:00' as datetime)

Now, you can also simply use the built-in getdate() function to bring back the current system time.

select getdate()

And finally, I want to bring back a datetime from an actual table.
In this case, we will use the employee table from the SQL Training Online Simple DB:
select hire_date from employee

If we want to convert the result to a more formatted string, we will use the TSQL CONVERT function:

select convert(varchar,hire_date,104)
from employee

In this example, we are converting from a datetime to a varchar (string). The result will be in the format of 104.

To translate 104 to a datetime format, you will want to look at the MSDN Documentation.

If you enjoy the video, please give it a like, comment, or subscribe to my channel.

READ THE ORIGINAL ARTICLE WITH SQL SCRIPTS HERE
http://www.sqltrainingonline.com/

YOUTUBE NEWS UPDATES
   / sqltrainingonline  

VISIT SQLTRAININGONLINE.COM FOR MORE VIDEO NEWS & TIPS
http://www.sqltrainingonline.com

SUBSCRIBE FOR OTHER SQL TIPS AND NEWS!
http://www.youtube.com/subscription_c...

SUBSCRIBE TO OUR EMAIL LIST!
http://www.sqltrainingonline.com

LET'S CONNECT!
Facebook:   / sqltrainingonline  
Twitter:   / sql_by_joey  
Linkedin:   / joeyblue  
SQLTrainingOnline: http://www.sqltrainingonline.com


Смотрите видео How to Use Datetime in SQL - SQL Training Online - Quick Tips Ep33 онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Joey Blue 19 Октябрь 2012, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 43,872 раз и оно понравилось 342 людям.