tags:

views:

7831

answers:

6

I need to select a datetime column in a table. However, I want the select statement to return the datetime as a nvarchar with the format DD/MM/YYYY.

+2  A: 

This should help. It contains all (or most anyway) the different date formats

http://wiki.lessthandot.com/index.php/Formatting_Dates

I think you'd be better off handling the string conversion in client if possible.

AlexCuse
+1  A: 
select convert(nvarchar(10), datefield, 103)
tsilb
and the format of that output is?
Joel Coehoorn
The format for that is exactly what the OP asked for and is in the language of the DB that was specified. I'm not sure what the down votes are all about.
Tom H.
The op edited the post after the comment- downvote revoked.
Joel Coehoorn
+7  A: 

Assuming sql server, here is the convert documentation:
http://msdn.microsoft.com/en-us/library/ms187928.aspx

Looking through that, it looks like you want style 103:

 SELECT CONVERT(nvarchar(10), getdate(), 103)
Joel Coehoorn
The OP requested NVARCHAR
Tom H.
so he did. fixed it
Joel Coehoorn
is there any occasion where this is not as simple as putting an "n" in front of varchar?
AlexCuse
+1  A: 

Geez, I type too slowly...

select CONVERT (NVARCHAR, GETDATE(), 103)
Ken Gentle
+1  A: 

Look up convert in BOL.

HLGEM
+1  A: 

Use Convert with the 103 option.

Turnkey