Week Month calc

Hello All,

Anyone have a good way of calculating the week number within the context of a given month/year?
I need to know if it is week 1 through 4 or 5 for a given month/year.

Thanks.

things we’d need to know

  1. what day do you consider “the first day of the week” ? Sun ? Sat ? Mon ?
  2. do you count partial weeks ? if Jan 1 is on a weds is that counted as week 1
  3. what if jan 1 is on some other day other “the first day of the week”

something you’d think is straight forward has a fair number of wrinkles

Sorry about the lack of info.

  1. Sunday
  2. & 3. I will defer to Xojo’s Date.WeekOfYear function meaning that if says a given date falls in week “X” then that is fine with me.
    Does that make sense?

Oh, I know it is problematic.

why not just create a new date with the date given then check the week of year property on the date object ?
that gives you the week of year

for the month can you just mod by 7 ?

Forgive me Norman, but I am being dense this AM.
I get the first part of your statement, but the second one is not making any sense to me.
Sorry. :-/

Mod in DevCenter :stuck_out_tongue:

But i also don’t get it, @Craig Boyd :smiley:

Thanks Sascha.

function WeekOfMonth(dt as date) as integer
dim first_of_month as new date
first_of_month.totalseconds=dt.totalseconds
first_of_month.day=1
return (dt.WeekOfYear-first_of_month.WeekOfYear)+1
end function

is That what you want?

Hi Dave,

Yes, that works well.

Thanks!

take the current day number (1-31) and divide Not mod) by 7

(daynumber \ 7)+1 => week number in the current month