Sign in to follow this  
Followers 0
SpiceGuy

Seeking '@YDAY' calculation for dates other than today

5 posts in this topic

@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 this post


Link to post
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 this post


Link to post
Share on other sites

#3 ·  Posted (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 by Chimp

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by SpiceGuy

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Chimp

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0