Solved

Format Time in MS SQL Server 2012 Query

Posted on 2013-12-04
8
286 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now