C#今天和日期字段之间的天数 [英] c# number of days between today and date field

查看:266
本文介绍了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.


这篇关于C#今天和日期字段之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆