Sql 上一年的周数
我是一名探视护士,有一个探视计划Access 2016数据库。一份报告使用周数分组“本周谁到期”供我查看。目前,一些患者已经过了到期日,他们的“下一个到期日”是2016年,他们的“周号”是2016年的51、52或53……uggh 分组中是否有办法将2016年日期设置在报告的顶部,因为其日期和“旧”日期为2016年,同时保留2017年的排序?也就是说,先显示过期的2016年日期,然后显示2017年日期 报表的源是表的查询。在此查询中,我有: NV_wknum:DatePart(“ww”,([上次S访问]+60)) 作为该特定条目的周号(NV为下次就诊,即上次就诊后60天)Sql 上一年的周数,sql,vba,date,ms-access,Sql,Vba,Date,Ms Access,我是一名探视护士,有一个探视计划Access 2016数据库。一份报告使用周数分组“本周谁到期”供我查看。目前,一些患者已经过了到期日,他们的“下一个到期日”是2016年,他们的“周号”是2016年的51、52或53……uggh 分组中是否有办法将2016年日期设置在报告的顶部,因为其日期和“旧”日期为2016年,同时保留2017年的排序?也就是说,先显示过期的2016年日期,然后显示2017年日期 报表的源是表的查询。在此查询中,我有: NV_wknum:DatePart(“ww”,([上次S
2016年日期显示在报告末尾,因为周数为51等。根据ISO 8601标准,此函数将返回任何给定日期的年数和周数:
Public Function ISO_WeekYearNumber( _
ByVal datDate As Date, _
Optional ByRef intYear As Integer, _
Optional ByRef bytWeek As Byte) _
As String
' Calculates and returns year and week number for date datDate according to the ISO 8601:1988 standard.
' Optionally returns numeric year and week.
' 1998-2007, Gustav Brock, Cactus Data ApS, CPH.
' May be freely used and distributed.
Const cbytFirstWeekOfAnyYear As Byte = 1
Const cbytLastWeekOfLeapYear As Byte = 53
Const cbytMonthJanuary As Byte = 1
Const cbytMonthDecember As Byte = 12
Const cstrSeparatorYearWeek As String = "W"
Dim bytMonth As Byte
Dim bytISOThursday As Byte
Dim datLastDayOfYear As Date
intYear = Year(datDate)
bytMonth = Month(datDate)
bytWeek = DatePart("ww", datDate, vbMonday, vbFirstFourDays)
If bytWeek = cbytLastWeekOfLeapYear Then
bytISOThursday = Weekday(vbThursday, vbMonday)
datLastDayOfYear = DateSerial(intYear, cbytMonthDecember, 31)
If Weekday(datLastDayOfYear, vbMonday) >= bytISOThursday Then
' OK, week count of 53 is caused by leap year.
Else
' Correct for Access97/2000+ bug.
bytWeek = cbytFirstWeekOfAnyYear
End If
End If
' Adjust year where week number belongs to next or previous year.
If bytMonth = cbytMonthJanuary Then
If bytWeek >= cbytLastWeekOfLeapYear - 1 Then
' This is an early date of January belonging to the last week of the previous year.
intYear = intYear - 1
End If
ElseIf bytMonth = cbytMonthDecember Then
If bytWeek = cbytFirstWeekOfAnyYear Then
' This is a late date of December belonging to the first week of the next year.
intYear = intYear + 1
End If
End If
ISO_WeekYearNumber = CStr(intYear) & cstrSeparatorYearWeek & Format(bytWeek, "00")
End Function
您可以使用不同的周制。然后——在你的报告中——首先排序
Year(DateAdd("d",60,[Last S-Visit]))
然后
DatePart("ww",DateAdd("d",60,[Last S-Visit]))
如果60天意味着2个月,则添加月份:
Year(DateAdd("m",2,[Last S-Visit]))
然后:
DatePart("ww",DateAdd("m",2,[Last S-Visit]))
记住从驱动报表的查询中删除所有排序;必须在报告本身中指定排序。此函数将根据ISO 8601标准返回任何给定日期的年和周数:
Public Function ISO_WeekYearNumber( _
ByVal datDate As Date, _
Optional ByRef intYear As Integer, _
Optional ByRef bytWeek As Byte) _
As String
' Calculates and returns year and week number for date datDate according to the ISO 8601:1988 standard.
' Optionally returns numeric year and week.
' 1998-2007, Gustav Brock, Cactus Data ApS, CPH.
' May be freely used and distributed.
Const cbytFirstWeekOfAnyYear As Byte = 1
Const cbytLastWeekOfLeapYear As Byte = 53
Const cbytMonthJanuary As Byte = 1
Const cbytMonthDecember As Byte = 12
Const cstrSeparatorYearWeek As String = "W"
Dim bytMonth As Byte
Dim bytISOThursday As Byte
Dim datLastDayOfYear As Date
intYear = Year(datDate)
bytMonth = Month(datDate)
bytWeek = DatePart("ww", datDate, vbMonday, vbFirstFourDays)
If bytWeek = cbytLastWeekOfLeapYear Then
bytISOThursday = Weekday(vbThursday, vbMonday)
datLastDayOfYear = DateSerial(intYear, cbytMonthDecember, 31)
If Weekday(datLastDayOfYear, vbMonday) >= bytISOThursday Then
' OK, week count of 53 is caused by leap year.
Else
' Correct for Access97/2000+ bug.
bytWeek = cbytFirstWeekOfAnyYear
End If
End If
' Adjust year where week number belongs to next or previous year.
If bytMonth = cbytMonthJanuary Then
If bytWeek >= cbytLastWeekOfLeapYear - 1 Then
' This is an early date of January belonging to the last week of the previous year.
intYear = intYear - 1
End If
ElseIf bytMonth = cbytMonthDecember Then
If bytWeek = cbytFirstWeekOfAnyYear Then
' This is a late date of December belonging to the first week of the next year.
intYear = intYear + 1
End If
End If
ISO_WeekYearNumber = CStr(intYear) & cstrSeparatorYearWeek & Format(bytWeek, "00")
End Function
您可以使用不同的周制。然后——在你的报告中——首先排序
Year(DateAdd("d",60,[Last S-Visit]))
然后
DatePart("ww",DateAdd("d",60,[Last S-Visit]))
如果60天意味着2个月,则添加月份:
Year(DateAdd("m",2,[Last S-Visit]))
然后:
DatePart("ww",DateAdd("m",2,[Last S-Visit]))
记住从驱动报表的查询中删除所有排序;必须在报告本身中指定排序