如何计算asp.net中从开始日期到结束日期的总天数 [英] how to calculate total days from start date to end date in asp.net

查看:106
本文介绍了如何计算asp.net中从开始日期到结束日期的总天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用asp.net c#javascript



我有开始日期和结束日期,如何显示完成和剩余的几个月。例如





2年2个月7天完成









1年2个月3天剩余

解决方案

你的名单C#,javascript和SQL - 但这是三种不同的解决方案。



对于C#来说很简单:只需从EndDate中减去DateTime.Now以获得剩余的,并且

格式化它返回的TimeSpan。过去是相同的,但反之亦然。



对于SQL来说它更复杂:使用SQL Server获取年,月,日和小时两个日期之间的持续时间 [ ^ ]



javascript也不是很好: http://stackoverflow.com/questions/17732897/difference-between-two-dates-in-years-months-days-in-javascript [ ^

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

解决方案

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[^]


这篇关于如何计算asp.net中从开始日期到结束日期的总天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆