如何计算两个日期之间的差异 [英] How to calculate difference between two dates

查看:176
本文介绍了如何计算两个日期之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算两个日期之间的差,结果应为Year,Month和Date格式.在计算差额时,还应该以结束日期为准.

例如:01/09/2012-30/09/2012 = 1个月
01/02/2012-29/02/2012 = 1个月
01/08/2012-10/08/2012 = 1个月10天
01/01/2012-31/12/2012 = 1年
01/01/2012-10/01/2013 = 1年10天

I want to calculate the difference between two dates and the result should get in Year,Month and Date format. While calculating the difference, it should take the end day also.

eg: 01/09/2012 - 30/09/2012 = 1 Month
01/02/2012 - 29/02/2012 = 1 Month
01/08/2012 - 10/08/2012 = 1 Month and 10 Days
01/01/2012 - 31/12/2012 = 1 Year
01/01/2012 - 10/01/2013 = 1 Year and 10 days

推荐答案

检查这些链接:

http://stackoverflow.com/questions/338463/how- do-i-do-a-date-comparison-in-javascript [ http://stackoverflow.com/questions/492994/compare-dates-with-javascript [ ^ ]

他们两个人都有很好的信息和好的建议.

我只是用Google搜索"javascript比较日期".
Check those links:

http://stackoverflow.com/questions/338463/how-do-i-do-a-date-comparison-in-javascript[^]
http://stackoverflow.com/questions/492994/compare-dates-with-javascript[^]

Both of them have nice information and good advice.

I''ve simply used Google searching "javascript compare dates".


http://www.javascriptkit.com/javatutors/datedifference.shtml [ http://www.htmlgoodies.com/html5/javascript/calculating-the-difference-between-two-dates-in-javascript.html#fbid=XMA8p-rX-H4 [
How to calculate difference between two dates using JavaScript[^]
http://www.javascriptkit.com/javatutors/datedifference.shtml[^]
http://www.htmlgoodies.com/html5/javascript/calculating-the-difference-between-two-dates-in-javascript.html#fbid=XMA8p-rX-H4[^]


如果您在vb.net中注册,那么这是一个解决方案...
DateDiff(DateInterval.Year,DTPDob.Value,DTPIncorpDT.Value)
if you r in vb.net then here is a solution...
DateDiff(DateInterval.Year, DTPDob.Value, DTPIncorpDT.Value)


这篇关于如何计算两个日期之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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