Age & Anniversary Calculations

Peter Haworth pete at lcsql.com
Wed May 23 01:50:23 EDT 2012


HI Igor,
I don't know the answer to your question about dates prior to 1970 on
Windows machines, but I do know that problem doesn't exist with the sqlite
solution I posted.  You don't even have to have an sqlite database
available to you, just call revOpenDatabase with ":memory:" as the file
path.  That creates an empty database in memory (no disk file) which
disappears when your application closes, but will accept the SELECT
statements.  I use sqlite like this for any date calculations and it's
never let me down yet, much more precise and succinct than any LC solution.
Pete
lcSQL Software <http://www.lcsql.com>



On Tue, May 22, 2012 at 10:00 PM, Igor de Oliveira Couto <
igor at superstudent.net> wrote:

> Many thanks for all the suggestions - and I did learn a couple of new
> tricks from your code, too! I had not realised that there could be an issue
> with pre-1970 dates in Windows, and also did not know that we had to watch
> out for the 'centuryCutoff' property. Very, very useful to know.
>
> Peter's code seems to be the most succinct - and flexible - for
> calculating the age:
>
> On 22/05/2012, at 6:01 AM, Peter M. Brigham, MD wrote:
>
> > function doAge tDate,asOf
> >   -- returns the age given birthdate = <tDate>
> >   -- as of the date <asOf> (if empty, assumes today)
> >   if tDate = empty then return empty
> >   if asOf = empty then
> >      put the date into asOf
> >   end if
> >   set the itemdelimiter to "/"
> >   put item -1 of the short date into nowYr
> >   set the centurycutoff to nowYr+1
> >   set the itemdelimiter to comma
> >   convert tDate to dateItems
> >   convert asOf to dateitems
> >   put item 1 of asOf - item 1 of tDate - 1 into tAge
> >   put item 1 of asOf into item 1 of tDate
> >   convert tDate to seconds
> >   convert asOf to seconds
> >   if tDate <= asOf then add 1 to tAge
> >   return tAge
> > end doAge
>
> This, however, does not seem to handle the 'before 1970' problem in
> Windows - ie., 'convert tDate to dateItems' here should fail in Windows, if
> tDate is before 1970. Is that correct, or am I missing something obvious?
>
> --
> Igor Couto
> Sydney, Australia
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list