• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Format Time in MS SQL Server 2012 Query

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
Lorrec
Asked:
Lorrec
  • 3
  • 2
  • 2
1 Solution
 
JimFiveCommented:
Maybe:
SELECT CONVERT(datetime, Time, 101)
0
 
UnifiedISCommented:
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
 
LorrecAuthor Commented:
Thank you. This is what I needed.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
LorrecAuthor Commented:
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
 
JimFiveCommented:
Lorrec should accept the response that helped him.
0
 
UnifiedISCommented:
I agree with JimFive, it appears that one or both of our comments were helpful in resolving the problem.
0
 
LorrecAuthor Commented:
Thank you for the assistance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now