Solved

SQL Datetime Output Format

Posted on 2009-05-04
6
647 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
'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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 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