Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Khargesh RajputRank #616 · 3.9K reputationPosted Apr 15, 2015, 10:22 PM EDT
Pankil BhattRank #2,947 · 489 reputationPosted Apr 15, 2015, 9:57 PM EDT
Then the following code would do the job:
DateTime startDate = new DateTime(2010, 1, 1);
DateTime endDate = new DateTime(2013, 1, 10);
var totalDays = (endDate - startDate).TotalDays;
var totalYears = Math.Truncate(totalDays / 365);
var totalMonths = Math.Truncate((totalDays % 365) / 30);
var remainingDays = Math.Truncate((totalDays % 365) % 30);
Console.WriteLine("Estimated duration is {0} year(s), {1} month(s) and {2} day(s)", totalYears, totalMonths, remainingDays);
Sameer KhanRank #8,108 · 228 reputationPosted Apr 15, 2015, 10:07 PM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 15, 2015, 10:41 PM EDT
Gowtham RajamanickamRank #57 · 29K reputationPosted Apr 15, 2015, 10:48 PM EDT
Abrar Ahmad AnsariRank #3,390 · 425 reputationPosted Apr 16, 2015, 12:49 AM EDT
DateTime todaydate = DateTime.Now;
int diff = todaydate.Subtract(firstdate).Days;
Manoj BhoirRank #599 · 4K reputationPosted Apr 16, 2015, 1:29 AM EDT
This code will help you :
int mStartYear = 2015; // Pass as per your requirement
int mLastYear = 2015; // Pass as per your requirement
DateTime mStartDate = new DateTime(mStartYear, 1, 1);
DateTime mEndDate = new DateTime(mLastYear, 12, 31);
double mDays = (mEndDate - mStartDate).TotalDays + 1;
MessageBox.Show(mDays.ToString());