Wednesday, April 18, 2007

Handy SQL Server Query: Date String For Filename

Here's a simple piece of code for creating a string in YYYYMMDDHHMMSS format, suitable for use as a filename:

REPLACE(REPLACE(REPLACE(CONVERT(char(19), GETDATE(), 120), ' ', ''), '-', ''), ':', '')

If you ran this at 1:23:05 PM on December 3, 2006, it would return "20061203132305".

1 comment:

Anonymous said...

Many thanks,
Saved me a couple of hours!
Rickard, Sweden