scorpio1102 发表于 2013-9-18 16:09:23

(已解决)知道@year&@yday怎么计算它的@year&@mon@mday

本帖最后由 scorpio1102 于 2013-9-20 08:22 编辑

如题:比如20130918是13年的261天,那么2013261转换成20130918怎么写,给个思路吧.

破帽遮颜 发表于 2013-9-18 16:49:16

Local $iday = 261
$sJulDate = _DateToDayValue (2013, 1, 1)
Dim $Y, $M, $D
$sJulDate = _DayValueToDate ($sJulDate+$iday, $Y, $M, $D)
MsgBox(4096, "", "14 days ago:" & $M & "/" & $D & "/" & $Y & " ?(" & $sJulDate & ")")

seniors 发表于 2013-9-19 21:16:46

这是2013261转换成20130918的数学转换方式,并不是楼上的代码,只是我从代码中知道可能看_DayValueToDate可以知道数学方式。
鉴定如下,楼上答非所问

xms77 发表于 2013-9-19 22:31:04

本帖最后由 xms77 于 2013-9-19 22:37 编辑

回复 1# scorpio1102
笨办法就是凑日子来算,呵呵!

#include <Date.au3>

Local $Date = _Date_Countday2Date(2012366)
MsgBox(0, 0, $Date)

Func _Date_Countday2Date($iCountDay)
        Local $Month = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
        Local $MDay = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"]
        If Not StringRegExp($iCountDay, "\d+", 0) Then Return MsgBox(16, "Error", '数据无效')
        Local $Year = StringLeft($iCountDay, 4)
        Local $CountDay = Int(StringTrimLeft($iCountDay, 4))
        If $CountDay > 366 Then Return MsgBox(16, "Error", '数据无效')
        For $i = 0 To 11
                For $j = 0 To 30
                        If _DateDiff('D', $Year & "/01/01", $Year & "/" & $Month[$i] & "/" & $MDay[$j]) = $CountDay-1 Then
                                Return $Year & $Month[$i] & $MDay[$j]
                        EndIf
                Next
        Next
EndFunc   ;==>_Date_Countday2Date

user3000 发表于 2013-9-19 22:41:03

本帖最后由 user3000 于 2013-9-19 22:43 编辑

2楼的思路复杂化了. 直接以 2013/1/1 加天数就得出结果了.
当然,如果要分别得到年月日三个变量的值, 还是用2楼的代码吧
2013/09/18 是第260天.#include 'date.au3'
Local $iday = 260
MsgBox(0, '', _DateAdd('D', $iday, '2013/1/1'))

scorpio1102 发表于 2013-9-20 08:14:02

本帖最后由 scorpio1102 于 2013-9-20 08:24 编辑

多谢各位的集思广益,以下是参考2楼与帮助手册解的方法.
#include <Date.au3>
; (Julian date).
;consolewrite(@MON)
;consolewrite(@MDAY)
Local $sJulDate = _DateToDayValue(@YEAR, '01', '01')
MsgBox(4096, "", "Todays Julian date is: " & $sJulDate)

Local $Y, $M, $D
$sJulDate = _DayValueToDate($sJulDate+@YDAY-1, $Y, $M, $D)
MsgBox(4096, "", "what date is it @year&@yday:" & $M & "/" & $D & "/" & $Y & "(" & $sJulDate & ")")

4楼也辛苦了.
页: [1]
查看完整版本: (已解决)知道@year&@yday怎么计算它的@year&@mon@mday