SpiceGuy Posted October 23, 2014 Share Posted October 23, 2014 @YDAY returns a 3-digit number for the current day of the year. Does anyone have a similar calculation that will return the 3-digit number for any date supplied? Thanks! Link to comment Share on other sites More sharing options...
kaisies Posted October 24, 2014 Share Posted October 24, 2014 @YDAY returns a 3-digit number for the current day of the year. Does anyone have a similar calculation that will return the 3-digit number for any date supplied? Thanks! _DateDiff("d",$Whateverdateyouwant,@NOW) ? Link to comment Share on other sites More sharing options...
Solution Gianni Posted October 24, 2014 Solution Share Posted October 24, 2014 (edited) one of possible ways: #include <Date.au3> #include <MsgBoxConstants.au3> Local $MyDate = "2014/10/24" ; <- date to check ; Local $aMyDate, $aMyTime _DateTimeSplit($MyDate, $aMyDate, $aMyTime) Local $iDateCalc = _DateDiff('d', $aMyDate[1] & "/01/01", $MyDate) MsgBox($MB_SYSTEMMODAL, "", $MyDate & " is the " & $iDateCalc + 1 & "° day of the yerar") Edited October 24, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
SpiceGuy Posted October 24, 2014 Author Share Posted October 24, 2014 (edited) one of possible ways: #include <Date.au3> #include <MsgBoxConstants.au3> Local $MyDate = "2014/10/24" ; <- date to check ; Local $aMyDate, $aMyTime _DateTimeSplit($MyDate, $aMyDate, $aMyTime) Local $iDateCalc = _DateDiff('d', $aMyDate[1] & "/01/01", $MyDate) MsgBox($MB_SYSTEMMODAL, "", $MyDate & " is the " & $iDateCalc + 1 & "° day of the yerar") That's exactly what I need. Thanks! Edit: Since I wanted to always return a 3-digit number, I had to tweak your code slightly to left-pad shorter numbers with zeroes: #include <Date.au3> #include <MsgBoxConstants.au3> Local $MyDate = "2012/01/24" ; <- date to check ; Local $aMyDate, $aMyTime _DateTimeSplit($MyDate, $aMyDate, $aMyTime) Local $iDateCalc = _DateDiff('d', $aMyDate[1] & "/01/01", $MyDate) If StringLen($iDateCalc) < 3 Then $iDateCalc = StringLeft("000",3-StringLen($iDateCalc)) & ($iDateCalc + 1) EndIf MsgBox($MB_SYSTEMMODAL, "", $MyDate & " is the " & $iDateCalc & "° day of the yerar") Edited October 24, 2014 by SpiceGuy Link to comment Share on other sites More sharing options...
Gianni Posted October 24, 2014 Share Posted October 24, 2014 (edited) That's exactly what I need. Thanks! You are welcome Edit: Since I wanted to always return a 3-digit number, I had to tweak your code slightly to left-pad shorter numbers with zeroes: you can also use StringFormat("%03s", $iDateCalc) to easly format the number with 3 digits here, just for fun, also another way to calculate the DayOfTheYear: #include <Date.au3> #include <MsgBoxConstants.au3> Local $MyDate = "2014/10/24" ; <- date to check MsgBox($MB_SYSTEMMODAL, "using _DateDiff()", $MyDate & " is the " & _DayOfYear($MyDate) & "^ day of the yerar") MsgBox($MB_SYSTEMMODAL, "using _DateToDayValue()", $MyDate & " is the " & StringFormat("%03s", _DayOfYear2($MyDate)) & "^ day of the yerar") ; Func _DayOfYear($MyDate) ; way 1 If $MyDate = "" Then $MyDate = _NowCalcDate() Local $aMyDate, $aMyTime _DateTimeSplit($MyDate, $aMyDate, $aMyTime) Return StringFormat("%03s", _DateDiff('d', $aMyDate[1] & "/01/01", $MyDate) + 1) EndFunc ;==>_DayOfYear Func _DayOfYear2($MyDate) ; way 2 If $MyDate = "" Then $MyDate = _NowCalcDate() Local $aMyDate, $aMyTime _DateTimeSplit($MyDate, $aMyDate, $aMyTime) Return _DateToDayValue($aMyDate[1], $aMyDate[2], $aMyDate[3]) - _DateToDayValue($aMyDate[1], 1, 1) + 1 EndFunc ;==>_DayOfYear2 Bye Edited October 24, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now