Week Numbers
BlitzMax Forums/BlitzMax Beginners Area/Week Numbers
| ||
I thought I better move this topic to a new thread, given it's gone off at a complete tangent.... :) http://www.blitzbasic.com/Community/posts.php?topic=59764 I'm happy to report that I have finally made some headway and I'm hoping that I'm finally on the right track to doing what I need. Will keep you posted - thanks for all the help and encouragement. :) |
| ||
. |
| ||
How to find week number: This is extracted from contracted work so I can't give you the actual source but here's the deal: 1. Find out what day of week 4th of January is. This date is always in week 1 ! 2. If 4Th of January is earlier in the week than Thursday we are still (January 1st) in week 52 or 53 of the previous year (Week starting on Monday) If #2 is true: 3. If in the previous year the 1st of January were a Thursday, then 1st of January this year are week 53 ! (Else 52) 4. If in the previous year the 1st of January were a Wednesday and last year were a leapyear, then 1st of January this year are week 53 ! (Else 52) I hope this makes sense to you, I have tested it on all years from 1772 (when Gregorian calendar was implemented in Norway) to 2099. (It should be good until 4099!) |
| ||
And this is my Leap-year function:'--------------------------------- Leapyear true or not Function leapyear#(aar#) ' Use year (YYYY) as arguement here Local tp If Int(aar/4) = aar/4 Then tp=True If Int(aar/100) = aar/100 Then tp=False If Int(aar/400) = aar/400 Then tp=True EndIf EndIf Return tp End Function |
| ||
How to find weekday of a specific date: (Also works between 1772 and 2099) '------------------------------- DOD (Day of date) Function dod$(day,month,year) ' (DD,MM,YYYY) Local d,a,m,y,tp$ a=14-month a=a/12 y=year-a m=month+(12*a)-2 d=(day+y+(y/4)-(y/100)+(y/400)+((31*m)/12)) Mod 7 Select d Case 0 tp$="Sunday " Case 1 tp$="Monday " Case 2 tp$="Tuesday" Case 3 tp$="Wednesday " Case 4 tp$="Thursday" Case 5 tp$="Friday " Case 6 tp$="Saturday " End Select Return tp$ ' Return day End Function |
| ||
wedoe, 1. Find out what day of week 4th og January is. This date is always in week 1 ! 2. If 4Th of January is earlier in the week than Thursday we are still in week 52 or 53 of the previous year (Week starting on Monday) Damn I wish I was at home so I could check this against my code. :) I'm pretty sure my code tells me how the 1st of January related to the first Thursday in Jan - which also has to be in week 1. If #2 is true: 3. If in the previous year the 1st of January were a Thursday, then 1st of January this year are week 53 ! (Else 52) 4. If in the previous year the 1st of January were a Wednesday and last year were a leapyear, then 1st of January this year are week 53 ! (Else 52) Thanks for that - I'll see how this relates to my code when I get chance. I got as far as determining whether the 1st of Jan was in week 1, or week 52/53 but not as far as whether it was 52 or 53 - if that makes sense? Nice one though, you've given something extra to work with much appreciated. :) Thanks for the other codes snippets, again appreciated. I already have functions for determining leapyear and day name. Your leapyear function works very similar to my own - I guess it would really. Thanks again. :) |
| ||
I also have a snippet somewhere calculating Easter day of any Gregorian year, do you need it ? (Made in BB3D, I think, but should be easy to convert) I need myself a function for moon-phases for Gregorian years but have not managed to create anything viable yet, maybe you could help me with this one ? |
| ||
please include a "Days_until_Xmas()" function |
| ||
I also have a snippet somewhere calculating Easter day of any Gregorian year, do you need it ? (Made in BB3D, I think, but should be easy to convert) That maybe useful at some point, but I'll leave it for now - I'd like to get the week number thing finished of 1st. Just had a go at it and pretty much got the code to determine the length fof the previous year with the help of your posting - thanks very much. :) I need myself a function for moon-phases for Gregorian years but have not managed to create anything viable yet, maybe you could help me with this one ? I have to say that means nothing to me TBH, perhaps again it's something I can look into once I've done what I intend to with this date thing first? |
| ||
bradford6 please include a "Days_until_Xmas()" function Take a look at another post I made relating to this... http://www.blitzbasic.com/Community/posts.php?topic=60038 and in particular the date.DayCount(DD, MM, YYYY) command. You could do what you want with simply... days_until_xmas% = date.DayCount(25,12,2006>) -date.DayCount() Is that what you were after? :) |
| ||
I was being silly... but cool! could you add a "Days until bradford6's birthday" and have a reminder pop up on everyones PC? :) |
| ||
I have to say that means nothing to me TBH, perhaps again it's something I can look into once I've done what I intend to with this date thing first? That's OK, I thought maybe you had it covered since you work with calendars right now :o)It's pretty much the only function I miss in my calendar functions folder... Just had a go at it and pretty much got the code to determine the length fof the previous year with the help of your posting - thanks very much. :) Glad to help, that's what these forums are for :o) |
| ||
could you add a "Days until bradford6's birthday" and have a reminder pop up on everyones PC? Not without knowing when your Birthday is no. ;-) |
| ||
Not without knowing when your Birthday is no. ;-) He is not even here!, neither are you Blitzer 101 ! |
| ||
He is not even here!, neither are you Blitzer 101 ! Ah, but then I've not been a BM user for very long. ;-) |
| ||
Never too late... |
| ||
Just posted on the age post. August 20th, 1970 maybe a very intrusive pop-up that automagically links to a 'bradford6 wish list' on Newegg.com I want to make it easy for folks to buy me fresh PC gear for my b'day :) |