Jump to content

CF to return week number between two date range


This topic is 6106 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi All

There is proby an existign CF I could re-jig, but I want to create a function which returns the NUMBER of a WEEK from a startDate to myDate... ie, how many weeks between startDate and myDate

Something like

WeekOfTerm (startDate ; myDate)

startDate is the date in the first week and could be any day M-F (or even Sat or Sun)(by default if myDate = startDate then WeekOfTerm = 1... but I also want it to work so that if myDate falls in the same Mon-Sun week as startDate it also returns 1.

I want to fix it so that regardless of when the dates fall the function deals with whole weeks at a time.

Eg. if startDate falls on a thursday then if myDate = startDate //returns 1

if myDate = the Friday after, then still returns 1

however if myDate = the following monday I want it to return 2.

Link to comment
Share on other sites

Hmmm, I got it to work okay if the starting day falls on a monday... thanks to Jason L. DeLooze of Nocturnal MicroSystems...

WeekOfTerm (StartDay ; StartMonth ; MyDate)

Let(

[

d = Date(StartMonth;StartDay;Year(MyDate)) ;

dp = Date(StartMonth;StartDay;Year(MyDate)-1) ;

s = d + Mod(StartDay-DayOfWeek( d )+3;7)-3 ;

sp = dp + Mod(StartDay-DayOfWeek( dp )+3;7)-3 ;

FY_Start = Case( MyDate >= s ; s ; sp )

] ;

Int( (MyDate - FY_Start)/7) + 1

)

Just don't know how to make it count part of a week as the first week...

Andrew

Link to comment
Share on other sites

Cheers Michael, your calc returns the number OF WEEKS between the two dates... but I want to calculate the ordinal number OF THE week, where the week of the startDate = 1, (where weeks are Mon - Sun)and so on...

Edited by Guest
Link to comment
Share on other sites

This topic is 6106 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.