首页 > 解决方案 > 无法比较来自 CRM 和 Excel 的 2 个日期时间

问题描述

我在比较和的DateTime值时遇到了问题。CRMExcel

1. DateTime excelDT1 = Convert.ToDateTime(row[Excel.notificationdate].ToString().Trim(), System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat); ;
2. var excelDT2 = row[Excel.notificationdate].ToString().Trim();
3. var excelDT3 = row[Excel.notificationdate];

4. DateTime crmDT1 = Convert.ToDateTime(caseEntity.Attributes[Case.notificationdate].ToString().Trim(), System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat); ;
5. var crmDT2 = caseEntity.Attributes[Case.notificationdate].ToString().Trim();
6. var crmDT3 = caseEntity.Attributes[Case.notificationdate];

下面分别是输出:

  1. excelDT1:2020 年 1 月 13 日上午 12:00:00
  2. excelDT2:13/01/2020
  3. excelDT3:13/01/2020


  4. crmDT1:2020 年 12 月 1 日下午 4:00:00

  5. crmDT2:2020 年 1 月 12 日下午 4:00:00
  6. crmDT3:2020 年 1 月 12 日下午 4:00:00

我可以知道如何格式化上述内容,以便可以检查它们是否存在equal

谢谢你。

标签: c#datetimecrm

解决方案


您可以将 1st 和 4th 与public static bool Equals (DateTime t1, DateTime t2);

var result = DateTime.Equals(excelDT1, crmDT1);

推荐阅读