15,513,463 members
1.00/5 (1 vote)
See more:
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)
{
}

if(nextBirthday < DateTime.Today)
{
}
```
Posted
Updated 3-Apr-17 23:59pm
Swinkaran 4-Apr-17 5:00am
Your question is little confusing. As per my understanding you want to know how to find the number of days between two dates? Is that what you want?
Parmendra choudhary 4-Apr-17 5:08am
I am sure about date is 25 but month and year should be changed.

I want to calculate days from recent 25 date, Month and year should be changed

## Solution 1

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

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

v2
Parmendra choudhary 4-Apr-17 5:06am
This is for fixed month.

I want to calculate from recent 25 date. not (27, 3, 25)

I am sure about date is 25 but month and year should be changed
OriginalGriff 4-Apr-17 5:18am
:sigh:
Then use TryParse or TryParseExact...the dates were just as a demo to show you what the subtraction did.
Parmendra choudhary 4-Apr-17 5:25am
I am not sure how is it resolve my problem. :((
OriginalGriff 4-Apr-17 5:47am
Try to explain your problem in simple terms - we seem to be talking at cross purposes.
For example, the code you show bears no relation to the description you seem to be trying to give ...
Parmendra choudhary 4-Apr-17 6:14am
I have resolved my problem

Thanks for help