4 Replies Latest reply on Aug 7, 2017 2:14 AM by fawad001

# How to count Month start and End Date ?

I have three Buttons, "Previous Month", "Current Month" and "Next Month", I want that by clicking these buttons, start and end date of months should calculate.

For Example

When I click on "Current Month" button the start date "01/08/2017" and end date "31/08/2017" should calculate, same like that, it should work for previous and next month, for previous month the dates should be  "01/07/2017" and end date "31/07/2017" and on other, for next month it should be start date "01/09/2017" and end date "30/09/2017".

Thanks.

• ###### 1. Re: How to count Month start and End Date ?

A little known trick with dates in FileMaker:

• You can add one to the month and use 0 (zero) as the day. That gives you the LAST day of the previous month.

firstDay = Date ( Month(myDate) ; 1 ; Year(myDate) )

lastDay = Date ( Month(myDate) + 1 ; 0 ; Year(myDate) )

FileMaker will take care of leap days and years!  Using the Date() function also takes care of the format of dates according to your system. If you use

dd/mm/yyyy

or

mm/dd/yyyy

the date will be correct.

Beverly

Sent from miPhone

2 of 2 people found this helpful
• ###### 2. Re: How to count Month start and End Date ?

Use the same logic to increment (Next Month) or decrement (Previous Month):

Let (

[ curDate = Get ( CurrentDate )

; curMon = Month (curDate)

; curDay = Day (curDate)

; curYr = Year (curDate)

; thisFirst = Date ( curMon ; 1 ; curYr )

; thisLast = Date ( curMon + 1 ; 0 ; curYr )

; nextFirst = Date ( curMon + 1 ; 1 ; curYr )

; nextLast = Date ( curMon + 2 ; 0 ; curYr )

; prevFirst = Date ( curMon - 1 ; 1 ; curYr )

; prevLast = Date ( curMon ; 0 ; curYr )

]; prevFirst & "..." & prevLast

// ; nextFirst & "..." & nextLast

// ; thisFirst & "..." & thisLast

)

Beverly

2 of 2 people found this helpful
• ###### 3. Re: How to count Month start and End Date ?

Thank you, Beverly.

• ###### 4. Re: How to count Month start and End Date ?

Really useful, thanks, Beverly.