How to convert Years into Days in asp .net
How to convert Years into Days in asp .net
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manoj BhoirPosted Apr 16, 2015, 5:29 AM
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());
Abrar Ahmad AnsariPosted Apr 16, 2015, 4:49 AM
DateTime todaydate = DateTime.Now;
int diff = todaydate.Subtract(firstdate).Days;
Gowtham RajamanickamPosted Apr 16, 2015, 2:48 AM
Munesh SharmaPosted Apr 16, 2015, 2:41 AM
Khargesh RajputPosted Apr 16, 2015, 2:22 AM
Sameer KhanPosted Apr 16, 2015, 2:07 AM
Pankil BhattPosted Apr 16, 2015, 1:57 AM
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);