【发布时间】:2015-11-22 02:14:52
【问题描述】:
我正在编写一个训练数据库。
学生有一个 ServiceDate(他们开始在公司工作的那一天)。
我需要从他们的 ServiceDate 了解他们是否在去年参加了特定课程。不是日历年,参加某些课程的需要会在周年纪念日重置……所以截止日期因每个学生而异。
我想我可以做这样的事情......但我确信有一个更简单的方法来做到这一点:
iDiff = cint((Date() - ServiceDate)/365) 'Gives the number of years between the ServiceDate and today
dMostRecent = DateAdd("yyyy",iDiff, ServiceDate) 'Uses the mm/dd from ServiceDate, but makes it the current year
If dMostRecent > Date() then 'If the new date is in the future...
dMostRecent = DateAdd("yyyy",-1,dMostRecent) 'Subtract 1 year
End If
'dMostRecent should now be within the last 12 months and I can check the dates that the given course was last taken and compare
有没有更简单的方法可以做到这一点......或者有人发现这种方法有问题吗?处理日期有时会很痛苦...
【问题讨论】:
-
闰年有超过 365 天
-
非常正确,但只有 1 天的差异,而且只是一年的一小部分。我不认为这很重要......但我可能是错的。