Sign in to follow this  
Followers 0
supersonic

Return day name for year day

6 posts in this topic

Hi everybody!

Is there a way to return a day name (1 to 7, Monday to Sunday) for a year day (1 to 365, resp. 366)?

For any given year and/or year day.

Currently I'm messing around with DATE.AU3 but without luck... :graduated:

Anyone any idea?

Greets,

-supersonic.

Share this post


Link to post
Share on other sites



1. Get the Julian date of the first day of the given year with _DateToDayValue()

2. Add your annual Julian date - 1 to that to get the full Julian date (days since noon January 1, 4713 BC)

3. Convert to Gregorian date with _DayValueToDate()

4. Use the Gregorian date to get the day of the week with _DateToDayOfWeek()

Sounds awkward, so maybe someone knows a shortcut.

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I am not sure what the thing is you are looking for but when you know what day 1 is you also know what day 8, 15 ,22 etc is.

Maybe you could first exactly explain what your input is and what result you expect.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You can do it so:

#Include <Date.au3>
ConsoleWrite(_DayInYearToWeekDay(2010, 60) & @CRLF)

Func _DayInYearToWeekDay($iYear, $iDayNumber, $fRetAsStr=True)
    Local $sDate = _DateAdd('D', $iDayNumber -1, $iYear & '/01/01')
    Local $aDate = StringSplit($sDate, '/', 2)
    If Not $fRetAsStr Then Return _DateToDayOfWeekISO($aDate[0], $aDate[1], $aDate[2])
    Switch _DateToDayOfWeekISO($aDate[0], $aDate[1], $aDate[2])
        Case 1
            Return 'Monday'
        Case 2
            Return 'Tuesday'
        Case 3
            Return 'Wednesday'
        Case 4
            Return 'Thursday'
        Case 5
            Return 'Friday'
        Case 6
            Return 'Saturday'
        Case 7
            Return 'Sonday'
    EndSwitch
EndFunc

??? - Whats that? - It's impossible to set tags.

Edited by BugFix

Best Regards BugFix  

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I have shorten BugFix' code! Posted Image

#include <Date.au3>
ConsoleWrite(_DayInYearToWeekDay(2010, 100) & @CRLF)

Func _DayInYearToWeekDay($iYear, $iDayNumber, $fRetAsStr = True)
    Local $sDate = _DateAdd('D', $iDayNumber -1, $iYear & '/01/01')
    Local $aDate = StringSplit($sDate, '/', 2)
    If Not $fRetAsStr Then Return _DateToDayOfWeek($aDate[0], $aDate[1], $aDate[2])
    Return _DateDayOfWeek(_DateToDayOfWeek($aDate[0], $aDate[1], $aDate[2]))
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

I always have problems getting "date things" right :graduated:

Thank you so far, the code examples and explanations working fine! :(

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