question

jhowe avatar image
jhowe asked

convert current datetime into ddmmyyyyhh24miss

hi how do I convert a datetime into the above format? This format doesn't seem to be a standard sql format... Thanks!
sql-server-2008sql-server-2008-r2
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
Without wanting to know why :) This snippet, concatenates the 103 style (dd/mm/yyyy) with the 114 style (hh:mi:ss:mmm(24h)), truncated after 8 characters to lose the ':mmm', then does 2 replaces over the whole thing to remove the '/'s and ':'s select replace( replace( convert(varchar, getdate(), 103) + left(convert(varchar, getdate(), 114),8), '/',''), ':','')
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jhowe avatar image jhowe commented ·
i'm using it to put it into a filename, the supplier wants it in this format, god knows why... thanks! I didn't think it was straightforward when I was looking at the available styles!
0 Likes 0 ·
jhowe avatar image jhowe commented ·
My colleague just informed me you were at the last sql bits (liverpool) and i might have actually spoken to you at some point without realising, i'll say hello next time I see you!
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
Interesting! Definitely say hello next time! Who is your colleague, would I know them?
0 Likes 0 ·
jhowe avatar image jhowe commented ·
exactly what i wanted... thanks...
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.