VBScript DateDiff月 [英] VBScript DateDiff month

查看:85
本文介绍了VBScript DateDiff月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取两个日期之间的月份日期差异时遇到问题。
这是一个示例:

I am having a problem about getting the month datedifference between two dates. Here is a sample:

DateDiff("m","2014-10-17","2014-10-30")

上面的代码返回0个月,因为它不到一个月。但是,

The above code returns 0 months since it is less than a month. But,

DateDiff("m","2014-10-17","2014-11-01")

返回1,因为它仍然是15天,所以不应返回。

returns 1 which should not be since it is still 15 days.

我的问题是我想看看这两个日期是否已经超过一个月,但似乎只有当日期的月份部分更改时,它才计算1个月。

My problem is I want to see if these two dates already exceed a month but it seems that it calculates 1 month only when the month part of the date is changed.

推荐答案

DateDiff 用第一个参数中定义的精度计算两个时间戳之间的跨度。从您在问题和评论中描述的内容来看,您似乎正在寻找这样的东西:

DateDiff calculates the span between two timestamps with the precision defined in the first parameter. From what you described in your question and comments you rather seem to be looking for something like this:

ds1 = "2014-10-17"
ds2 = "2014-10-30"

d1 = CDate(ds1)
d2 = CDate(ds2)

diff = DateDiff("m", d1, d2)
If diff > 0 And Day(d2) < Day(d1) Then diff = diff - 1

WScript.Echo diff & " full months have passed between " & ds1 & " and " & ds2 & "."

这篇关于VBScript DateDiff月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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