Jump to content

Seeking '@YDAY' calculation for dates other than today


 Share

Go to solution Solved by Gianni,

Recommended Posts

  • Solution

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 by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

 

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 by SpiceGuy
Link to comment
Share on other sites

 

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 by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...