T-SQL question
Author
Discussion

FunkyGibbon

Original Poster:

3,848 posts

288 months

Thursday 17th June 2004
quotequote all
Do anyone have a list of the “formatting codes” for the CONVERT function in t-sql for converting date formats?

The best I can find is by the powere of google is www.databasejournal.com/features/mssql/article.php/2197931

But it doesn’t have dd-mm-yyyy (which is the one I want)– any ideas?

TIA

FG

>>> Edited by FunkyGibbon on Thursday 17th June 09:11

plotloss

67,280 posts

294 months

Thursday 17th June 2004
quotequote all
The CONVERT function should have a Style parameter.

Style 101 is UK Format Date...

anonymous-user

78 months

Thursday 17th June 2004
quotequote all
Not ideal, but how about something like:

SELECT DAY(@date) + '-' + MONTH(@date) + '-' + YEAR(@date)

Although this won't prepend 0 to pad to 2 chars for day and month.

Wrap it up into a custom function and you could include code to pad to two chars if needed.

FunkyGibbon

Original Poster:

3,848 posts

288 months

Thursday 17th June 2004
quotequote all
plotloss said:
The CONVERT function should have a Style parameter.

Style 101 is UK Format Date...



cheers Matt!. That's the one I want - or is it?

Hmm, edited to add that just doing this seems to give me

mm/dd/yyyy



>> Edited by FunkyGibbon on Thursday 17th June 10:07

Don

28,378 posts

308 months

Thursday 17th June 2004
quotequote all
INSERT INTO FYHDR(FINISH_DATE) VALUES (CONVERT(SMALLDATETIME,'31 DEC 1999 00:00:00:000',13)))



Is this the sort of thing you wanted?

FunkyGibbon

Original Poster:

3,848 posts

288 months

Thursday 17th June 2004
quotequote all
Found it at last on MSDN...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp

style 105 gives me dd-mm-yyyy

thanks for the help guys