在帮助中有介绍,AU3中把周日算作一周的最后一天了。
成功: 返回一周中的星期几(范围1 到 7),1=Monday(星期一). 函数参考
--------------------------------------------------------------------------------
_DateToDayOfWeekISO
返回一个指定日期的国际标准(ISO)星期(n)数.
#Include <Date.au3>
_DateToDayOfWeekISO($iYear, $iMonth, $iDay)
参数
$iYear 一个有效的YYYY年格式
$iMonth 一个有效的MM月格式
$iDay 一个有效的DD日格式
返回值
成功: 返回一周中的星期几(范围1 到 7),1=Monday(星期一).
失败: 返回 0,并设置 @error
@error: 0 - 无错误.
1 - 输入的日期无效
如果想要把周日改成一周的第一天,需要手动把UDF改掉,把Date.au3中的两个函数改掉:
_DateToDayOfWeekISO
_WeekNumberISO
Func _DateToDayOfWeekISO($iYear, $iMonth, $iDay)
Local $idow = _DateToDayOfWeek($iYear, $iMonth, $iDay)
If @error Then
Return SetError(1, 0, "")
EndIf
Return $idow
EndFunc ;==>_DateToDayOfWeekISO
Func _WeekNumberISO($iYear = @YEAR, $iMonth = @MON, $iDay = @MDAY)
; Check for erroneous input in $Day, $Month & $Year
If $iDay > 31 Or $iDay < 1 Then
Return SetError(1, 0, -1)
ElseIf $iMonth > 12 Or $iMonth < 1 Then
Return SetError(1, 0, -1)
ElseIf $iYear < 1 Or $iYear > 2999 Then
Return SetError(1, 0, -1)
EndIf
Local $idow = _DateToDayOfWeekISO($iYear, $iMonth, $iDay) - 1;
Local $iDow0101 = _DateToDayOfWeekISO($iYear, 1, 1) - 1;
If ($iMonth = 1 And 4 < $iDow0101 And $iDow0101 < 7 - ($iDay - 1)) Then
;days before week 1 of the current year have the same week number as
;the last day of the last week of the previous year
$idow = $iDow0101 - 1;
$iDow0101 = _DateToDayOfWeekISO($iYear - 1, 1, 1) - 1;
$iMonth = 12
$iDay = 31
$iYear = $iYear - 1
ElseIf ($iMonth = 12 And 30 - ($iDay - 1) < _DateToDayOfWeekISO($iYear + 1, 1, 1) - 1 And _DateToDayOfWeekISO($iYear + 1, 1, 1) - 1 < 4) Then
; days after the last week of the current year have the same week number as
; the first day of the next year, (i.e. 1)
Return 1;
EndIf
Return Int((_DateToDayOfWeekISO($iYear, 1, 1) - 1 < 5) + 4 * ($iMonth - 1) + (2 * ($iMonth - 1) + ($iDay - 1) + $iDow0101 - $idow + 6) * 36 / 256)
EndFunc ;==>_WeekNumberISO
|