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
Post a Comment