即将到来的日期函数
Upcoming Date Function
我有 3 个不同的日期,我正在尝试编码最近的日期。如果日期是过去的,则需要忽略它。另外,date1 <= date2 <= date3
我已经尝试使用以下代码 (8/18/2021, 8/19/2021, 8/20/2021) 作为输入,但是函数 returns 12:00:00AM不是 2021 年 8 月 18 日
Public Function UpcomingDates(date1 As Date, date2 As Date, date3 As Date) As Date
Dim ClosestDate As Date
If date1 >= Date Then 'diff1 >= 0
ClosestDate = date1
ElseIf date2 >= Date Then
ClosestDate = date2
ElseIf date2 >= Date Then
ClosestDate = date3
End If
End Function
为什么函数 return 2021 年 8 月 18 日没有?
*我在 MS Access 查询中使用 VBA
日期作为序列号存储在 Access(和其他办公产品)中。例如,“1/1/2008”实际存储为 39448。数字 39448 是自 1900 年 1 月 1 日以来的天数。此数字的小数位表示一天中的时间。因此,假设没有小数的数据值是 12:00:00 AM。例如,39448.25 表示 1/1/2008 早上 6 点,39448.5 表示 1/1/2008 中午 12 点,依此类推
要使函数只显示日期,请使用格式函数:
Format(ClosestDate, "m/d/yyyy")
我有 3 个不同的日期,我正在尝试编码最近的日期。如果日期是过去的,则需要忽略它。另外,date1 <= date2 <= date3
我已经尝试使用以下代码 (8/18/2021, 8/19/2021, 8/20/2021) 作为输入,但是函数 returns 12:00:00AM不是 2021 年 8 月 18 日
Public Function UpcomingDates(date1 As Date, date2 As Date, date3 As Date) As Date
Dim ClosestDate As Date
If date1 >= Date Then 'diff1 >= 0
ClosestDate = date1
ElseIf date2 >= Date Then
ClosestDate = date2
ElseIf date2 >= Date Then
ClosestDate = date3
End If
End Function
为什么函数 return 2021 年 8 月 18 日没有?
*我在 MS Access 查询中使用 VBA
日期作为序列号存储在 Access(和其他办公产品)中。例如,“1/1/2008”实际存储为 39448。数字 39448 是自 1900 年 1 月 1 日以来的天数。此数字的小数位表示一天中的时间。因此,假设没有小数的数据值是 12:00:00 AM。例如,39448.25 表示 1/1/2008 早上 6 点,39448.5 表示 1/1/2008 中午 12 点,依此类推
要使函数只显示日期,请使用格式函数:
Format(ClosestDate, "m/d/yyyy")