Solved

Format Time in MS SQL Server 2012 Query

Posted on 2013-12-04
8
291 Views
Last Modified: 2013-12-06
Hello. My environment is MS SQL Server 2012. I am trying to get my query to output the time in a readable format. Currently, it outputs the time in the below format. I would like to have it output into something like 11-01-2013 or 2013-11-01. Is this possible?

20131101140039.000000-420

Below is my query.
SELECT Time
from v_GS_DEPLOYMENT
0
Comment
Question by:Lorrec
  • 3
  • 2
  • 2
8 Comments
 
LVL 15

Expert Comment

by:JimFive
ID: 39696684
Maybe:
SELECT CONVERT(datetime, Time, 101)
0
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 500 total points
ID: 39696697
I don't think SQL will recognize that as a valid datetime.  Is it a string data type of some sort?

This assumes there will always be 4 digit year, 2 digit month, 2 digit day to start the string:
SELECT LEFT(Time, 4) + '-' + SUBSTRING(Time, 5,2) + '-' + SUBSTRING(Time, 7,2)
0
 

Author Comment

by:Lorrec
ID: 39696713
Thank you. This is what I needed.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:Lorrec
ID: 39696744
I've requested that this question be closed as follows:

Accepted answer: 0 points for Lorrec's comment #a39696713

for the following reason:

Thank you for the quick response.
0
 
LVL 15

Expert Comment

by:JimFive
ID: 39696745
Lorrec should accept the response that helped him.
0
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 39697125
I agree with JimFive, it appears that one or both of our comments were helpful in resolving the problem.
0
 

Author Closing Comment

by:Lorrec
ID: 39701424
Thank you for the assistance.
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question