Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Format Time in MS SQL Server 2012 Query

Posted on 2013-12-04
8
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

718 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