减去日期并仅返回已过去的天数。 [英] subtracting dates and returning only the number of days that have passed.

查看:112
本文介绍了减去日期并仅返回已过去的天数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我想知道我如何减去2个日期并仅返回已经过的天数,例如3/22 / 2013-3 / 21/2013 = 1

hello guys i want to also know how i can subtract 2 date and return only the number of days that have erapsed for example 3/22/2013-3/21/2013=1

推荐答案

非常简单:



Quite simple :

DateTime start = new DateTime(1, 1, 2013);
DateTime end = DateTime.Now;
TimeSpan ts = end - start;
int totalDays = ts.TotalDays;





希望这个帮助。



抱歉,我没有注意标签。这里是VB.NET:





Hope this helps.

Sorry I didn''t make attention to the tag. Here''s in VB.NET :

Dim startDate As DateTime = New DateTime(1, 1, 2013)
Dim endDate As DateTime = DateTime.Now
Dim ts As TimeSpan = endDate - startDate
Dim totalDays As Integer = ts.TotalDays


这篇关于减去日期并仅返回已过去的天数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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