如何计算今天和上次提供日期之间的天数。 [英] How to calculate days between today and last provided date.

查看:242
本文介绍了如何计算今天和上次提供日期之间的天数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事银行业项目。我有以下条件。

假设任何人从2014年12月25日开始向我的银行投资

我想计算今天日期4/4/2017和最后一天之间的天数月投资日期即25/3 / 107.我如何计算2017年4月4日至2017年3月25日之间的天数。

我可以从system.datetime.now获得4/4/2017。

我最近几个月的投资情况还是我现在的月份。



我尝试了什么:



I am working on banking project. I have following condition.
Suppose any Person invest money into my bank from 25/12/2014
I want to calculate days between Today date 4/4/2017 and last month invest date i.e 25/3/107.How I calculate days between 4/4/2017 to 25/3/2017.
I can get 4/4/2017 from system.datetime.now.
How I get investment in recent month or it my be current month.

What I have tried:

System.DateTime birthday = DateTime.Parse("2/9/2012 10:10:11 AM");

    var nextBirthday = birthday.AddYears(DateTime.Today.Year - birthday.Day);
    var recentBirthday = birthday.AddMonths(DateTime.Today.Month - birthday.Month);



   if (recentBirthday<DateTime.Today)
   {
    recentBirthday = recentBirthday.AddMonths(1);
   }


   if(nextBirthday < DateTime.Today)
   {
    nextBirthday = nextBirthday.AddYears(1);
  }

推荐答案

尝试:

Try:
DateTime dtStart = new DateTime(2017, 3, 25);
DateTime dtEnd = DateTime.Now.Date;
TimeSpan diff = dtEnd - dtStart;
Console.WriteLine(diff.TotalDays);





奇怪...忽略HTML标签 - 它们似乎是一个bug,我会报告......



Odd...ignore the HTML tags - they appear to be a bug, I'll report it...


这篇关于如何计算今天和上次提供日期之间的天数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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