sql server - Convert int MMDDYYYY into datetime MM-DD-YYYY -


i convert int mmddyyyy (e.g.-5112012) datetime mm-dd-yyyy , convert datetime mm-dd-yyyy yyyy-mm-dd or if above can done in 1 step converting int mmddyyyy datetime yyyy-mm-dd?

for reference, earlier converted int yyyymmdd datetime yyyy-mm-dd using following syntax:

declare @date int; set @date = 19900511 select convert(datetime, convert(varchar(8),@date), 103) 

declare @date int; set @date = 5112012 select convert(datetime, left('0' + convert(varchar(8), @date), 2) + '-' + substring( '0' + convert(varchar(8), @date), 3, 2) + '-' + right(@date,4)) 

that bails water, fix leak; change storage int proper date or datetime :)


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -