4 Replies Latest reply on Oct 25, 2012 11:09 AM by hobbiesdeveloper

# Date Range Calculations

### Title

Date Range Calculations

### Post

Hello,

I need to find out what calculations to use to for getting this week range.

We currently have the Range Start Field with a date and a Range End Field with a date, as well as the Date Range Option Drop Down List to select if you would like This Week, Last Week, Next Week, This Month, Last Month, Next Month to show order records?

I'm currently using a script for each Date Range to set fields for the Range Start and Range End Date but not sure what calculation to use to get "This Week", "Last Week", "Next Week", "This Month", "Last Month", "Next Month".

Please let me know what the best calculation option, i'm sure you would need to use the Get( CurrentDate ).

• ###### 1. Re: Date Range Calculations

What date marks the start of your week? Sunday?

Let ( T = Get ( CurrentDate ) ;
T - DayOfweek ( T ) + 1 )

will compute the Sunday date of this week. Add 6 to that and you've got Saturday of the same week.

Subtract 7 to get the preceding week, Add 7 to get next week.

Let ( T = Get ( CurrentDate ) ;   T - Day ( T ) + 1 )

Will compute the date of the first of this month.

Let ( T = Get ( CurrentDate ) ; Date ( 0 ; Month ( T ) + 1 ; Year ( T ) ) )

Will return the date of the last day of this month.

Let ( [ T = Get ( CurrentDate ) ; Date ( 1 ; Month ( T ) - 1 ; Year ( T ) ) )

will be the date for the first of Last Month

Let ( [ T = Get ( CurrentDate ) ; Date ( 0 ; Month ( T )  ; Year ( T ) ) )

Will be the date for the last day of last month.

Let ( [ T = Get ( CurrentDate ) ; Date ( 1 ; Month ( T ) + 1 ; Year ( T ) ) )

First of Next Month

Let ( [ T = Get ( CurrentDate ) ; Date ( 0 ; Month ( T ) - 2 ; Year ( T ) ) )

End of Next Month

• ###### 2. Re: Date Range Calculations

Monday Marks the Start of a new week.

• ###### 3. Re: Date Range Calculations

Let ( T = Get ( CurrentDate ) ;
T - DayOfweek ( T ) + 2 )

• ###### 4. Re: Date Range Calculations

Thanks.