age calculation on Windows vs Mac

Bill Vlahos bvlahos at mac.com
Tue Jul 19 19:24:15 EDT 2011


The problem is the epoch date in Windows is 1970 and LiveCode can't deal with dates earlier than that in Windows. You will need to use a VBScript.

Here is what I use in InfoWallet which handles Windows, Mac, and Linux correctly which was based on code provided by folks on this list.

on calcAge tDate,asOf
   -- returns the current age based on a DOB of tDate
   -- as of the date asOf, or if asOf = empty, as of today
   if tDate = empty then return empty
   if the platform is "WIn32" then
      isADate tDate
      if the result then
         put "sdate = " & quote & tDate & quote into vFive
         put return & "result = DateDiff(" & quote & "d" & quote & ",sdate,Date)" after vFive
         put return & "trueage = result / 365" after vFive
         put return & "result = Left(trueage,2)" after vFive
         do vFive as vbscript
         return the result
      else
         return empty
      end if
   else
      if tDate is not a date 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 if
end calcAge


Bill Vlahos
_________________
InfoWallet (http://www.infowallet.com) is about keeping your important life information with you, accessible, and secure.

On Jul 19, 2011, at 9:23 AM, André Bisseret wrote:

> Bonjour,
> 
> I am a Mac user but I recently bought a PC (windows 7) in order to test my standalones for windows more quickly.
> 
> I am fighting for hours now with the following problem :
> 
> In an app., I have a handler that calculates the age  from the short birth date  (thanks to Jim Ault who gave it on the list).
> The birth date is jj/mm/AAAA or jj/mm/AA as well.
> 
> This handler works fine on Mac, but not on windows. 
> 
> On windows, the age is invariably 100 if the birth year < 1970. (with JJ/MM/AA or JJ/MM/AAAA (as bad ;-(
> If the birth year > = 1970 then the age is correct.
> 
> I tried to play with the centuryCutOff but without any success (on windows).
> 
> I am not familiar with Windows : what am I missing ? Is it a matter of computer setting or should I program differently for windows than for mac !?
> 
> Thanks a lot in advance for any help
> 
> Best regards from Grenoble
> 
> André
> 
> P.S. By the way, I used to use a search engine (if I well remember, it was in the help menu of livecode) I do not find it any more; has it been suppressed ? (or here again, I am missing something !)
> _______________________________________________
> 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