Solved

SQL Datetime Output Format

Posted on 2009-05-04
6
648 Views
Last Modified: 2012-05-06
I am trying to adjust an SQL query to output in a specific Datetime format. I am close but it needs to output in British Format: dd/mm/yyyy HH:MM:SS.
I have it except there are spaces where the "/" are. I need the / displayed in the output
 
Here is the code I am using
  CASE
      When vSF.ModifiedDate is Null then '""'
      Else ('"' + ltrim(convert(char(20), vSF.ModifiedDate,13)) + '"')
 END,

So I imagine I have to combine it with a formatting string of some sort?
0
Comment
Question by:raddermant
  • 3
  • 2
6 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24297106
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24297107
Use :
CONVERT(char(10), ModifiedDate, 103) + ' ' + CONVERT(char(8), ModifiedDate, 108)
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24297150
Try:
CONVERT(NVARCHAR, vSF.ModifiedDate, 131)
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 24297154
So your code would look like this:
CASE
      When vSF.ModifiedDate is Null then '""'
      Else ('"' + CONVERT(char(10), vSF.ModifiedDate, 103) + ' ' + CONVERT(char(8), vSF.ModifiedDate, 108) + '"')
END,

Also, 14 has a 2 digits for the year and MMM for the month, which is not the same as yours: dd/mm/yyyy HH:MM:SS
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24297158
Nice idea, AC.  
0
 

Author Comment

by:raddermant
ID: 24630118
The exact final soulution ended up as:

["Access Date"]=
CASE
                When vSF.ModifiedDate is Null then '""'
                Else ('"' + ltrim (CONVERT(char(10), vSF.ModifiedDate,103)) + ' ' + (CONVERT(char(8),vSF.ModifiedDate, 108))+ '"')
END,
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Have a conversion issue with varchar to int in a SQL: Query. 1 47
Syntax for query to update table 2 39
Complex Query - help please 5 60
Union & Crosstab qrys 101! 6 52
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…

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