Solved

Format Time in MS SQL Server 2012 Query

Posted on 2013-12-04
8
289 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what are the unique tables in SQL master database 5 62
Create snapshot on MSSQL 2012 3 21
Weighted Randomizing 6 16
Sql query with where clause 2 15
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

832 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