Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary.
Military Time Format
From Wiki
This WiKi entry is based on a recent question asked at MSDN forum Custom String Format
In order to create a time string using military format in T-SQL we can use two T-SQL functions DatePart and DateName and also a well known technique of padding value to left using RIGHT function.
- declare @d datetime = getdate()
- --ddHHmmMMMyy.toUpper (military format).
- --That is two digit day, two digit hour, two digit minute, three letter month, two digit year, and month is uppercase.
- select Right('00' + cast(DATEPART(day,@d) as varchar(2)),2) +
- Right('00' + cast(DATEPART(hour,@d) as varchar(2)),2) +
- Right('00' + cast(DATEPART(minute,@d) as varchar(2)),2) +
- upper(left(DATENAME(month,@d),3)) + RIGHT(cast(DATEPART(year,@d) as varchar(4)),2)
Contributed by: --Naomi 21:41, 14 April 2010 (GMT)
LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.