保险类型的日期在SQL Query与CRM比较后落后1天?

时间:2017-06-27 09:48:18

标签: sql sql-server

我在下面有一个SQL查询,它在SQL查询中从CRM保险类型到期日期落后1天。 CRM中保险类型的到期日为2017年4月4日,在查询时间为2017年3月3日,请告知我现在使用UTC吗?

select CASE mm_insurance.mm_insurancetype   

WHEN 930720000 THEN 'Airside Liability Insurance' 
WHEN 930720001 THEN 'Contractors All Risks' 
WHEN 930720002 THEN 'Employers Liability Insurance' 
WHEN 930720003 THEN 'Product Liability Insurance' 
WHEN 930720004 THEN 'Professional Indemnity Insurance' 
WHEN 930720005 THEN 'Public Liability Insurance' 
WHEN 7930720006 THEN 'Removals and Storage Liability'

ELSE ''

END AS InsuranceType, Format(mm_insurance.mm_expirydate , 'dd/MM/yyyy') as InsuranceExpiry

from mm_insurance where mm_account =  '40600D69-068A-E611-810E-005056956082' and mm_expirydate between '03/04/2017' AND '05/04/2017'

you can see the results as 03/04/2017 when I should be getting 04/04/2017

结果是2017年4月3日,我应该到04/04/2017

3 个答案:

答案 0 :(得分:0)

这应该指导您解决问题:

Declare @Input_Utc_Date as Datetime = GETUTCDATE();
Select 
DATEADD(MILLISECOND,DATEDIFF(MILLISECOND,getutcdate(),GETDATE()),@Input_Utc_Date) as UTC_To_LocalTime

输出:

input(UTC)               UTC_To_LocalTime 
2017-06-27 10:54:25.480 | 2017-06-27 16:24:25.480

答案 1 :(得分:0)

这也是将UTC转换为当地时间的解决方案。

Declare @myDateUtc datetime = '2017-06-27 12:00'

select GETDATE()-GETUTCDATE()+@myDateUtc myDateLocal

答案 2 :(得分:0)

尝试此查询,这应该是您的后续内容,建议在开发报告时使用过滤后的视图。

select CASE mm_insurance.mm_insurancetype   

WHEN 930720000 THEN 'Airside Liability Insurance' 
WHEN 930720001 THEN 'Contractors All Risks' 
WHEN 930720002 THEN 'Employers Liability Insurance' 
WHEN 930720003 THEN 'Product Liability Insurance' 
WHEN 930720004 THEN 'Professional Indemnity Insurance' 
WHEN 930720005 THEN 'Public Liability Insurance' 
WHEN 7930720006 THEN 'Removals and Storage Liability'

ELSE ''

END AS InsuranceType, Format(mm_expirydate , 'dd/MM/yyyy') as InsuranceExpiry

from Filteredmm_insurance AS mm_insurance where mm_account = @AccountId and mm_expirydate between @ExpiryClauseFrom AND @ExpiryClauseTo