VBScript DateDiff month

前端 未结 2 1329
半阙折子戏
半阙折子戏 2021-01-24 01:06

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\")

2条回答
  •  太阳男子
    2021-01-24 01:06

    You can calculate day difference between two dates using 'DateDiff("d",date1,date2)'. Then calculate number of full-month by dividing 30 days.

    Following is an example.

    monthDiff = int(DateDiff("d","2014-10-17","2014-11-01") / 30)
    

    As you know, days of months differs by month. For example, November has 30 days and December has 31 days.

    If you wish to use 30 days a month when first day is on November, and to use 31 days a month whe first day is on December, the code need a table of days of months and routine to handle month information.

提交回复
热议问题