Sunday, September 9, 2007

Common UK DateTime Formats

Some common DateTime conversions I use -

SELECT CONVERT(varchar(10), getdate() , 103) 

09/09/2007

SELECT CONVERT(varchar(10), getdate() , 120) 

2007-09-09

SELECT CONVERT(varchar(20), getdate() , 120) 

2007-09-09 12:18:29

strip non-numeric characters (e.g to use datetime in a filename) -
SELECT REPLACE(REPLACE(REPLACE(CONVERT(varchar(20), getdate() , 120),'-',''),' ',''),':','')

20070909123203

No comments: