Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Shortcut for Displaying All DateTime Conversion Styles

Status
Not open for further replies.

DaveInIowa

Programmer
Dec 2, 2003
576
US
There have been times when I’ve needed a specific format for a DateTime value but don’t have the different style values memorized. Instead of doing a search on the CONVERT function each time, I created this query shortcut and thought I’d share.

Go to (SSMS 2014) ...
[tt]Tools > Options… > Environment > Keyboard > Query Shortcuts[/tt]

Paste the following into one of the shortcuts (for example, Ctrl+7)
[tt]DECLARE @Now DATETIME2(7) = SYSDATETIME(); SELECT Style, CONVERT(VARCHAR, @Now, Style) [CONVERT(VARCHAR, @Now, Style)] FROM (VALUES (0), (100), (101), (102), (103), (104), (105), (106), (107), (108), (9), (109), (110), (111), (112), (13), (113), (114), (20), (120), (21), (121), (126), (127), (130), (131)) s(Style)[/tt]

Now, when you have a query window open, you can press the query shortcut and see the current date/time in all of the available styles in the Results window.
 
Ought to be in an FAQ.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top