Help

103 views
Skip to first unread message

Gwyn Richards

unread,
Oct 26, 2025, 12:48:14 PMOct 26
to Sailforms Users
How do you display an age between two dates as years months days ?
Gwyn 

Paul Bowers

unread,
Oct 26, 2025, 5:56:54 PMOct 26
to Sailforms Users
Hope this helps. Import the dates.xml load form.

Sailform provides an age function which returns the difference in years. 

To go more granular you need to cover the date to a timetable on seconds.
Subtract the two timestamps. Then convert back from seconds to days. 

You can then computer years by dividing 365. Compete months by a
 rough divide by 31 then days by subtracting the day cashier of the original
Dates. 

As month day s is not a constant (it changes month to month) it could get
complex if you need to be more accurate. 
Screenshot_20251026_215113_Pro.jpg
Dates.xml

Gwyn Richards

unread,
Oct 27, 2025, 5:52:31 AMOct 27
to Sailforms Users
Hi Paul
Thanks for the reply.
I realise that could divide the result into 3 fields, but i was wondering if a Timestamp
Format could be applied to a single field, as my previous stopwatch example, to
display hours minutes seconds,
tstampFormat("HH:mm:ss ",toTimestamp(date(),0)+Stopwatch seconds)
I have tried combinations of yy:MM:dd as a Format with some weird results.
As my 80 year old brain is not so sharp, (although my daily dosage of Sailforms
keeps it working!) 1 thought this may be possible.
Gwyn

Gwyn Richards

unread,
Oct 27, 2025, 10:40:22 AMOct 27
to Sailforms Users
I now realise what i wanted to do is impossible,  I can't have zeros in day , month or year in Date or Timestamp fields. Which is what i wanted by subtracting 2 date fields.
Gwyn 

Doug Packer

unread,
Oct 28, 2025, 3:37:48 PMOct 28
to Sailforms Users
I think this works. I have not implemented LeapYear so, EndDates in March of leap years will sometimes yield incorrect 'Days' count 1 day.  I will play with that exception too but needed to feed cows.

Coding Strategy:
Enter any StartDate. EndDate must follow StartDate.

Use Sailforms commands, Day, Month and Year on input dates subtracting Start from End.  Negative values appear and the trigger exception analysis.  
 
I used If commands to solve these problems.

Linked MonthDay table to correct for variable days per month.
Jan 31
Feb 28
etc.

Use strategy:

Default layout is the display layout.
ScratchPad layout shows all fields hidden from default view.
Y_M_D_Age_1.sfg

Gwyn Richards

unread,
Oct 29, 2025, 4:53:49 AMOct 29
to Sailforms Users
Well done Doug,thanks,  that must have taken some brain time. Now you can relax and go back to your cows!
Gwyn 

Gwyn Richards

unread,
Oct 29, 2025, 11:29:07 AMOct 29
to Sailforms Users
Hi 
I've got the old brain box working and came up with this. It caters for leap years, the working outs are off screen to the right. 
Thank you for your solutions. 
Gwyn 

Elapsed.sfg

Gwyn Richards

unread,
Oct 29, 2025, 12:48:52 PMOct 29
to Sailforms Users
Oops just found a flaw in my year calculations. Back to the drawing board!

Gwyn Richards

unread,
Oct 30, 2025, 11:25:16 AMOct 30
to Sailforms Users
Try again
I don't know if it was a system bug, but Sailforms was adding an extra bracket) to year(Date)-year(Date) formulas. I was getting strange results, I did  a work around by adding extra fields. 
If there is a Date input error,  a warning will flash up for 3 seconds.
Gwyn 

Elapsed_v2.sfg

Doug Packer

unread,
Oct 31, 2025, 3:28:44 PMOct 31
to Sailforms Users

This version adjusts for a leap year (2/29) for the next 400, maybe 999 years. The algorithm for leap year changes at 4, 100, 400 years, all confirmed. I vaguely remembe it changes again at 1000 years but I could not confirm.
I fixed the bug in previous versions for the bouncing month lengths.  All these issues are directly addressed by measuring time in lapsed seconds - a path I did not use.   What's cool is, like so many things in life, there can be more than 1 solution.
Y_M_D_Age-v251031.sfg

MikeG

unread,
Nov 5, 2025, 10:09:27 AMNov 5
to Sailforms Users
Sorry not to have responded before now.  I'm nowadays only an occasional reader of this forum ( but am still a user of Sailforms).

Here's another solution for you.  It avoids any use of additional forms holding monthly data and does not require any processing loops.

It takes advantage of the toDate function to do most of the logic and needs just two hidden calculation fields.  All leap year processing gets handled automatically by Sailforms in toDate

Note:
toDate is very useful for date processing:
 - it allows you add or subtract months or days from a given date, automatically allowing for changes of year and for leap years, that is to add m months and d davs to date D:
         toDate(year(D),month(D)+d,days(D)+d)
 - it allows you to find the number of days in a month by looking at the date of the last day in the day before the 1st of the next month, that is for month M in year Y:
        day(toDate(Y,M+1,1)-1)
 - it allows you to check for a leap year, that is year Y is a leap year if:
         day(toDate(Y,3,1)-1)=29

Elapsed_YMWD.sfg

MikeG

unread,
Nov 5, 2025, 10:14:00 AMNov 5
to Sailforms Users
Oops!, sorry, that should have been 
       toDate(year(D),month(D)+m,days(D)+d)

Gwyn Richards

unread,
Nov 5, 2025, 10:20:42 AMNov 5
to Sailforms Users
Well done Mike 
I knew you would come up trumps!
I was concerned that we haven't heard from you for a while. 
Thanks 
Gwyn 

On Wednesday, 5 November 2025 at 15:09:27 UTC MikeG wrote:
Reply all
Reply to author
Forward
0 new messages