Click here to Skip to main content
15,513,463 members
Please Sign up or sign in to vote.
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
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);
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

1 solution

DateTime dtStart = new DateTime(2017, 3, 25);
DateTime dtEnd = DateTime.Now.Date;
TimeSpan diff = dtEnd - dtStart;

Odd...ignore the HTML tags - they appear to be a bug, I'll report it...
Share this answer
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    
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900