How to sql server difference query datetime varchar -
i have variable time, format varchar(8)
in sql server
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
Comments
Post a Comment