Jump to content

get current month in button bar calculation


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

Recommended Posts

I'm trying to set up a button bar that displays the current months names based on the following

 

Current month

Last month

Next Month

 

I can use Month (Get(current date)) - 1 (for example) but I get a number of 2 for february or 1 for january

If I use Monthname (Get (Currentdate) - 1 my result is (-1)

Thanks in advance, thanks!

Link to comment
Share on other sites

1 hour ago, Matthew R White said:

If I use Monthname (Get (Currentdate) - 1 my result is (-1)

If you subtract 1 from the current date, you get the date of yesterday, not a date in the previous month.
And if you subtract 1 from a month's name (text), then you get -1 (since text is evaluated as 0).

To calculate the name of the previous month, you can use =

MonthName ( Date ( Month ( Get ( CurrentDate ) ) - 1 ; 1 ; 2 ) )

 

 

Edited by comment
  • Like 1
Link to comment
Share on other sites

7 hours ago, comment said:

To calculate the name of the previous month, you can use =

MonthName ( Date ( Month ( Get ( CurrentDate ) ) - 1 ; 1 ; 2 ) )

 

Hi Michael!

Would you be so kind as to explain something for me?  Of course Get ( CurrentDate ) will never be empty, and since button bar is a layout object, it will always refresh that date (unlike a calculation field which must be checked as 'Do not store calculation results' when using Get ( CurrentDate ).  

My question ...  If I use a regular date field and if that date field is empty then it generates November.  I cannot spot the translation logic as to why!

Also, if regular date field is used as a calculation, it will not produce a result if your date field is empty because default is checked 'do not evaluate if all referenced fields are empty' so that is great.  But if regular date is used on button bar, it should be wrapped with an If() test to not display the result (or to display different default result) if empty because non-field calculations (button bar, script etc) can not take advantage of that 'do not evaluate' checkbox.

What fun! Thank you for always throwing surprises into the mix!  :smile3:

Is it as simple as Month 1 is January so Month 0 is December ... then previous month is November?

Edited by LaRetta
Link to comment
Share on other sites

5 hours ago, LaRetta said:

Is it as simple as Month 1 is January so Month 0 is December ... then previous month is November?

Yes, it is. You can see that:

Date ( Month ( "" ) - 1 ; 1 ; 2 )

is Nov 1, 0001. Strictly speaking, Month ( "" ) is not 0, but empty - but when you subtract a number from it, it's as good as.

 

 

  • Like 1
Link to comment
Share on other sites

This topic is 2312 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
 Share

×
×
  • Create New...

Important Information

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