计算两个日期之间的完整月份vb [英] count complete month between two dates vb

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

问题描述

     Dim a As new DateTime = 16/10/2017

    Dim b As new DateTime = 10/11/2017

    Dim a As new DateTime = 16/10/2017
    Dim b As new DateTime = 10/11/2017

Label38。 Text = DateDiff(DateInterval.Month,a,b).ToString& "月份

结果1个月

但我希望0除非一个完整的月份

but i want 0 unless one complete month

推荐答案


但我想要0,除非一个完整的月份b

but i want 0 unless one complete month

DateDiff的规则是" DateInterval.Month 的返回值纯粹来自年份和月份部分参数"。 因此,如果月份相差1,那么返回值为1. 如果您想要实施
不同的规则,那么您需要考虑该月的某一天。 例如,如果结束日期的月份日期小于开始日期的月份日期,则从返回值中减去1。

The rule for the DateDiff is "the return value for DateInterval.Month is calculated purely from the year and month parts of the arguments".  So if the months differ by 1 then the return value is 1.  If you want to implement a different rule then you need to consider the day of the month.  For instance, if the day of the month for the end date is less than the day of the month for the start date, then subtract 1 from the return value.


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

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