【发布时间】:2014-11-16 23:41:11
【问题描述】:
我正在尝试在模块中使用 Access 2013 为季节(夏季、冬季、车辙)定义日期戳。 “季节”在不同年份具有相同的开始和结束日期,定义如下。
11/15 to 3/5 = Winter
3/16 to 10/15 = Summer
10/16 to 11/14 = Rut
下面包含的函数首先处理空值,然后将日期时间戳格式化为简单的月日(即 11 月 15 日被格式化为 11/15)。
然后我定义 tmpSeason as a String 并使用嵌套的 If 语句将每个日期范围分类到相应的季节。问题就在这里。尽管代码运行,但它会生成一个包含所有“Winter”值的列。我怀疑错误源于使用 >= 或 时缺少一年
Function Season(GPSFixTime)
Dim tmpDt As Date
If (IsNull(GPSFixTime) = True) Then
Exit Function
Else
End If
tmpDt = DateSerial(Mid(GPSFixTime, 1, 4), Val(Mid(GPSFixTime, 6, 2)), Val(Mid(GPSFixTime, 9, 2)))
tmpDt = tmpDt + ((tmpHr / 24) - 7 / 24) 'To correct the time to local time in winter
tmpDt = Format(tmpDt, "mm/dd") ' Format to remove year
Dim tmpSeason As String
If (tmpDt >= 11 / 15 Or tmpDt <= 2 / 15) Then
tmpSeason = "Winter"
Else
If (tmpDt >= 3 / 15 Or tmpDt <= 10 / 15) Then
tmpSeason = "Summer"
Else
If (tmpDt > 10 / 15 Or tmpDt < 11 / 15) Then
tmpSeason = "Rut"
End If
End If
End If
Season = tmpSeason
End Function
任何关于如何将日期正确分类为季节的想法都将不胜感激。
这是我关于 VBA 的最初帖子之一,我欢迎在发布功能性帖子时提供反馈。
【问题讨论】:
-
先判断是VBA还是VB.NET,然后是北半球还是南半球