How to sql server difference query datetime varchar -


i have variable time, format varchar(8) in sql server

enter image description here

how result ? try datediff.. can not it.. because variable type varchar...

sql server 2008 r2

before using datediff use convert function convert varchar data date

select datediff(dd,convert(date,date2),convert(date,date1)) yourtable 

if have bad data cannot converted date may have filter out data before converting date.

if using sql server 2012+ use try_convert

select datediff(dd,try_convert(date,date2),try_convert(date,date1)) yourtable 

sqlfiddle demo


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -