C#今天和日期字段之间的天数

问题描述:

我正在尝试使用一个名为"ContractOfferQDays"的计算字段. (设置为Integer字段类型)在LightSwitch实体客户"中.感谢您的帮助.

I am trying to use a calculated field named "ContractOfferQDays" (set as an Integer field type) within a LightSwitch entity "Customer".  Thanks for any help. 

        partial void ContractOffer_Validate(EntityValidationResultsBuilder results)

        {
            int q;
            
            if (ContractOffer.HasValue && ContractRatified.HasValue)
            {
                q = ContractRatified - ContractOffer;
                ContractOfferQDays = q;
            }

            else
            {
                q = DateTime.Now - ContractOffer;
                ContractOfferQDays = q;
            }
            
            // results.AddPropertyError("<Error-Message>");

        }

      }

       }

使用

Using MSDN, subtracting two DateTime objects results in a TimeSpan object. On the TimeSpan object, there is a Days property, which gives you the whole number of days difference between the two DateTime objects.

您真的应该在中询问如何执行此操作 C#语言论坛,而不是LightSwitch论坛,因为您询问的是如何在C#中执行X"?它与LightSwitch无关.

You really should be asking how to do this in the C# language forum, not the LightSwitch forums, since you are asking "How do I do X in C#" and it has nothing to do with LightSwitch.