Date Woes

In 2104 r2 ( i think the date class is changed in r3?)

If I have two dates,

dDateJoined (as Date) and dDateQuit (as Date)

1… What is the fastest way to find out the number of days as a member?

Also Years old?

dBirthDay (as Date) dToday(asDate)

  1. What is fast way to figure out how old a persons?

Not unless you’re using the one in the new framework

(dDateQuit.totalSeconds - dDateJoined.totalseconds) / 86400

[quote=153196:@Jay Menna]
Also Years old?

dBirthDay (as Date) dToday(asDate)

  1. What is fast way to figure out how old a persons?[/quote]

This ones more tricky depending how precise you want to be

You could subtract birth year from current & get a “yer 10” even though their birthday hasnt yet passed
My mom gets this as she was born dec 30 so folks always overstate her age by a year

Note that this may not actually be days as calculated on a calendar due to daylight savings time changes, leap years, or leap seconds. The new Xojo.Core.Date class lets you subtract two dates to get a Xojo.Core.DateInterval object back.

For example, with the new Xojo.Core.Date class you can use this code to determine how old someone is:

  Using Xojo.Core
  
  Dim birthDay As New Date(2000, 6, 14, TimeZone.Current)
  
  Dim elapsed As DateInterval
  elapsed = Date.Now - birthDay
  
  Dim years As Integer = elapsed.Years // 14 years
  Dim months As Integer = elapsed.Months // 6 months
  Dim days As Integer = elapsed.Days // 3 days

Exactly - the OLD date had no built in way to account for the many of the vagaries that dates & times have.
The new one does so handles this much better.

One of those little things that until you have to do it and see how hard it is to do right you dont appreciate

I spent ages writing and testing a little piece of code to calc the years, months and days between two dates.
It worked but didn’t factor in leap years.
Now I can just use this!
Nice.

[quote=153317:@Norman Palardy]Exactly - the OLD date had no built in way to account for the many of the vagaries that dates & times have.
The new one does so handles this much better.

One of those little things that until you have to do it and see how hard it is to do right you dont appreciate[/quote]

There was quite an interesting debate a while ago https://forum.xojo.com/15374-getting-the-date-difference-in-years-months-days