sql - How to change date value format to YYYYMMDD format -
when creating sql backup/web viewer as400 data, of data had scrubbed hand.
in process, dates in database ended being stored strings in 2 formates:
yyyymmdd
mm/dd/yyyy
in effort preserve original data, convert of mm/dd/yyyy
yyyymmdd
. there query fix this? like:
select commentdate sometable if format(commentdate) '00/00/0000' commentdate = format(commentdate, '00000000')
first, highly recommend track down whoever decided store dates text , give him beating. you're welcome borrow time-travelling android, if helps.
you're there. using ms sql syntax:
select case when commentdate '[12][0-9][0-9][0-9][0-1][0-9][0-3][0-9]' convert(date, commentdate, 112) when commentdate '[0-1][0-9]/[0-3][0-9]/[12][0-9][0-9][0-9]' convert(date, commentdate, 101) end (select '20140410' commentdate union select '04/10/2014') x
Comments
Post a Comment