Calendar Calculation

132 views
Skip to first unread message

David Hooper

unread,
Jun 10, 2019, 8:36:40 AM6/10/19
to Sailforms Users
My wife doesnt like using Calendar apps on her phone, so I have developed an agenda program for my wife. Everything is working well and she can put in appointments that are daily, weekly, monthly, yearly, but I need a calculation for the same day of every month like the 1st Friday of every month. Any help?

MikeG

unread,
Jun 10, 2019, 2:48:42 PM6/10/19
to Sailforms Users
If field Date holds the first date that conforms to your required rules then add to your form 2 whole number fields as follows:
WD calculated by (day(Date)-1)/7
WD28 calculated by (day(Date+28)-1)/7

These give the week number 0 to 4 within the month of Date and of Date + 28 days.

You can now calculate your next date using
Date+if(WD=WD28,28,35)
That is you add 4 weeks to Date if the date 28 later has the same week-in-month value, or add 5 werks otherwise.

I tried to create the calculation without using the additional fields but this seemed to be too complicated for the Sailforms equation editor - it would not allow me to put brackets where I needed them.

Do you also need to be able to calculate the first date? If so, what information is available to this calculation?

Mike

Doug Packer

unread,
Jun 10, 2019, 3:36:22 PM6/10/19
to Sailforms Users
Hi David,

Perhaps you have already attempted something like this but first Friday is relatively easy compared to some more difficult 'picks'.

We know:

First Friday is some where between the 1st and the 7th of each month.

Sailforms 'weekday' is a command/function reporting what day of the week a particular date 'occupies'. (Friday = 6)

Sailforms 'todate' is a command/function that builds a date from year, month, and day. This and perhaps other commands has a play in your effort.

Sailforms 'if' command stacked into case series can help you find Friday (6).

I read your request for help just a few minutes ago. Building your solution may be easier broken down into several fields perhaps stored in a form that is feed a request and returns a date. This is all thinking without touching Sailforms.

Your request is a good one. I bet MikeG is working on the puzzle solution as I type this note. If not, I hope these ideas help you build your own.

Doug

David Hooper

unread,
Jun 10, 2019, 4:14:00 PM6/10/19
to Sailforms Users
Thx Doug and Mike. I was half-way there and I think it will get me what I need. Also, I'm begining to save little database routines such as this as separate databases so I don't have to rewrite. I hope to just copy them to a new group.

Appreciate your help.

MikeG

unread,
Jun 10, 2019, 4:15:48 PM6/10/19
to Sailforms Users
Hi Doug and David,
Despite the description in the SF help in Edit Form, the SF weekDay function returns not a number (1 = Sunday, ...) but a 3-character text string (Sun, Mon, ...).

If you want a numeric value for day of week use Date%7 (where Date is your date field). This gives a value 0 to 6 (0 = Monday, ..., 6 = Sunday).

Mike

Message has been deleted

Doug Packer

unread,
Jun 11, 2019, 1:23:50 AM6/11/19
to Sailforms Users
I attached a good start...I think
DatePicker_1.sfg

Doug Packer

unread,
Jun 11, 2019, 2:09:09 PM6/11/19
to Sailforms Users
DatePicker allows one to enter a year, a month, a day, and finally the 'Day instance' within a month.

One can obtain the date of the 3rd Friday of September, 2020.


It could be used as a 'called form' that returns the found date for your specifications. This may help implementation because establishing the various hidden fields and the equations in your form is a fairly heavy job.

I suspect MikeG. will find a simpler solution but I found taking incremental steps with smaller equations easier for me. Doing that created several hidden fields.

If one was inclined to do a re-build, I'd recommend making the hidden fields unsaved. In addition, I used 2 methods to swap between day name and day number. That too, could be cleaned up.

Lastly, GiveMeDate uses 2 form layouts. This is becoming a 'best practice' for me. The default layout FindTheDate is for run time and SupportingFields layout is for development work and debugging. This is easier than toggling hidden fields on and off.

Doug


MikeG

unread,
Jun 11, 2019, 5:14:33 PM6/11/19
to Sailforms Users
I think Doug is challenging me to find a simpler solution!!!

I'm not sure the attached is simpler, but it's different so it is probably worth looking at to get alternative ideas.

Mike

Monthly_Dates.sfg

Doug Packer

unread,
Jun 11, 2019, 7:15:01 PM6/11/19
to Sailforms Users
Mike,

I hope you enjoyed working the puzzle as much as I did. It made me turn off TV to focus. No, my comment was not intended to be a challenge. Instead, it was intended as a complement about your skill with Sailforms. Your reaction made me smile!

I don't see a big difference between the solutions on a complexity score. I DO see you used the more recent tools added to Sailforms. That means I need to open my eyes and play with them. Tools left un-used can't serve me.

Doug

MikeG

unread,
Jun 12, 2019, 2:52:58 AM6/12/19
to Sailforms Users
Yes Doug, I enjoyed the mental challenge.

Note:
My solution was going to include a "Last in month" option (which effectively means 5th if there is one, else 4th) bit I forgot about it so it doesn't work!

Mike

Reply all
Reply to author
Forward
0 new messages