程序计算c#.net中到期日期前1个月 [英] program To Calculate The 1 month Before The expiry Date in c#.net

查看:400
本文介绍了程序计算c#.net中到期日期前1个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有4列的表。

表名 - 人员详细信息

字段 - 名称,职位,开始日期和到期日。

我想要的是在1个月的到期日期之前,根据到期日,会​​有通知或弹出消息待续订。我不知道如何计算日期。谢谢..

I have a Table Which have 4 Columns.
Table Name- Personnel Details
Fields- Name, Position, Commence Date and Expiry Date.
What I want to make is before 1 month date for expiration which is based on Expiry Date there will be notice or pop up message "To be renew". I don't know how to calculate the date. Thanks..

推荐答案

只要到期日是一个DateTime对象,你就应该遇到相对较少的麻烦。现在,我假设你在客户端应用这个,看到你没有在你的标签中包含SQL Server或其他数据库,我不打算将此作为一个查询,我假设您已经检索过这些数据。假设您将到期日期映射到名为ExpiryDate的C#属性,那么您需要做的就是:
As long as Expiry Date is a DateTime object, you should have relatively little trouble. Now, I'm assuming here that you are applying this at the client side, seeing that you haven't included SQL Server or other database in your tags, I'm not going to cover doing this as a query and I'm assuming that you have retrieved this data already. Suppose you mapped Expiry Date into a C# property called ExpiryDate, then all you need to do is:
bool shouldRenew = ExpiryDate.AddMonths(-1) > DateTime.Now;


这可以通过日期差异来实现。 />
查看非常好的文章 [ ^ ]在那里给出。



或者更确切地说,

This can be achieved by date difference.
See a very good article[^] is given there.

or rather,
DateTime x1 = DateTime.ParseExact("20119", "yyyyM", CultureInfo.InvariantCulture);
DateTime x2 = DateTime.ParseExact("20135", "yyyyM", CultureInfo.InvariantCulture);

int months =  Math.Abs((x2.Month - x1.Month) + 12 * (x2.Year - x1.Year));



-KR


-KR


这篇关于程序计算c#.net中到期日期前1个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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