找回密码
 加入
搜索
查看: 1915|回复: 3

[AU3基础] 年的周数问题和一个星期认定问题,求解决方法??[已解决]

[复制链接]
发表于 2015-7-25 02:51:25 | 显示全部楼层 |阅读模式
本帖最后由 kk_lee69 于 2015-7-25 15:14 编辑

_WeekNumberISO("2015","07","05") 这个显示27周

但是   SELECT datepart(week,'20150705')
SQL 认为是 28周

20150705 为星期日 理论上应该是一周的开始不是??

为何会是27周呢??

求解 如何修正跟SQL 一樣呢??
发表于 2015-7-25 09:37:47 | 显示全部楼层
在帮助中有介绍,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
 楼主| 发表于 2015-7-25 15:19:09 | 显示全部楼层
回复 2# haijie1223

多謝提醒 倒是沒注意到那個說明
但是我覺得很怪的是 一個 UDF 幹麻前後 的邏輯不一樣
_DateDayOfWeek
天數. 取值範圍: 1 = 星期天(Sunday) 到 7 = 星期六(Saturday).

_DateToDayOfWeekISO
返回指定日期的周序數(範圍 1 到 7), 1 = 星期一(Monday).

用了_DateToDayOfWeekISO 在套入 _DateDayOfWeek
就會出現問題了
发表于 2015-7-26 07:12:04 | 显示全部楼层
谢谢二楼版主的修改,的确是应该修改成这样子
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 18:21 , Processed in 0.089056 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表