# Seeking '@YDAY' calculation for dates other than today

## Recommended Posts

@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!

##### Share on other sites

@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) ?

##### 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")```
Edited by Chimp

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

##### 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

##### 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

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

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...