Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CF to return week number between two date range

Featured Replies

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.

I don't think you need a custom function for this. Try:

Let (

monStart = StartDate - DayOfWeek ( StartDate - 1 ) + 1

;

Div ( EndDate - monStart ; 7 ) + 1

)

  • Author

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

  • Author

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

No, it returns the number of WHOLE weeks between the Monday on or before StartDate and EndDate, and adds 1 - I believe that is also the ordinal number you're looking for. If not, give an example where the result is different than expected.

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.