Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
by using asp.net c# javascript

i have start date and end date, how to show the years months days completed and remaining . for example


2 years 2 months 7 days completed

and


1 year 2 months 3 days remaining
Posted
Comments
CHill60 24-Jan-15 7:46am    
What have you tried so far? And why is SQL-Server tagged?
Zoltán Zörgő 24-Jan-15 8:09am    
On which layer do you need this? In T-SQL, in C# or in Javascript?

1 solution

You list C#, javascript, and SQL - but that is three different solutions.

For C# it's simple: Just subtract DateTime.Now from the EndDate to get the remaining, and
format the TimeSpan that it returns. The elapsed is the same, but the other way round.

For SQL it's more complex: Get Duration Between Two Dates in Years, Months, Days, and Hours using SQL Server[^]

And javascript is not very nice either: http://stackoverflow.com/questions/17732897/difference-between-two-dates-in-years-months-days-in-javascript[^]
 
Share this answer
 

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