Help please - date math

Henko
Posts: 804
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Help please - date math

Post by Henko »

We know, and rbyres started to point to your library. Steve tried it and could not succeed with it.
So, just pointing at it a second time will not be very helpfull 😉.

User avatar
rbytes
Posts: 1337
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Help please - date math

Post by rbytes »

I just calculated the number of days since my birth using each method. I think there is something wrong in all of them. It can't be that many!!!! :lol:
The only thing that gets me down is gravity...

Henko
Posts: 804
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Help please - date math

Post by Henko »

If you were born before january 1st, 2000, my function may indeed give wrong results

User avatar
rbytes
Posts: 1337
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Help please - date math

Post by rbytes »

Actually that is a relief!
The only thing that gets me down is gravity...

Bish99&@
Posts: 8
Joined: Sun Jan 28, 2018 4:30 am
My devices: iPad pro 10.5", iOS 11.2.5, MacBook Pro
Location: Richmond, Va., U.S.
Flag: United States of America

Re: Help please - date math

Post by Bish99&@ »

Thanks George for you help, but when I used this code it returned the wrong number. The difference between 1/21/2018 and 2/03/2018 should be 14 days, this function returned 24. I don't know what the problem is.


PRINT g(2018,1,21) - g(2018,2,3)
DEF g(y,m,d)
m = (m + 9) % 12
y = y - m/10
nd = INT(365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 ) )
RETURN nd
ENDDEF

REM Difference between two dates = g(y2,m2,d2) - g(y1,m1,d1)

Thanks again for you assistance.
Steve

Bish99&@
Posts: 8
Joined: Sun Jan 28, 2018 4:30 am
My devices: iPad pro 10.5", iOS 11.2.5, MacBook Pro
Location: Richmond, Va., U.S.
Flag: United States of America

Re: Help please - date math

Post by Bish99&@ »

I don't know if I made I clear earlier, but I was able to resolve my problem with the code from Henko and Rbytes; which used functions written by Dutchman (date dunctions library, and date calculator). I really thank everyone who read my request and responded. You're a good bunch of guys.

Steve

User avatar
rbytes
Posts: 1337
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Help please - date math

Post by rbytes »

It's nice to be thanked, Steve, and we stand ready to assist you again. You may get so advanced with Smart Basic we will need to ask you for help. ;)
The only thing that gets me down is gravity...

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Help please - date math

Post by GeorgeMcGinn »

I said you were showing it as an example, for I figured as such.

Did not mean to offend you for I know you math skills are great, some of the best complex code I've ever seen you've done with ease.

Henko wrote:
Sun Feb 04, 2018 8:36 am
Why limit the date to one after 1/1/2000 to present.

Below is a function that works for the Gregorian calendar. (People in English-speaking countries used a different calendar before September 14, 1752.)

When writing code, why limit it to 17 years? I know that you are showing it as an example, but if I wanted it to work for my birthday, or I wanted to display the number of days WWII lasted, your example is useless and working in base 11 is beyond most simple programmers.

Here is a more elegant formula that works with any date from 9/14/1752 to the present.

It also takes into consideration years that are and are not leap years.
Dear George,

Please reread the first thing i said in my message. It said that i made the function "for my own use". At the time i did not need to cover dates before 2000, and i was not aware of the nice function you presented here. I did not upload the function then precisely for that limitation.
So now you know why i made such a limited function, it fullfilled my own needs 100%.

In the mean time, thanks for pointing to the better and even shorter function, it will certainly replace mine in the data library (after testing if it works correctly😉).
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Help please - date math

Post by GeorgeMcGinn »

I'll take a look at it, but I used a well-known formula (well known to us mathematicians). If the formula is wrong, I'll have a paper to write. But i will make sure my formula does indeed math the source links I provided.

But you are using it wrong. You should swap your subtraction. Always subtract the earlier date from the most recent date. But even that gives a number short of 24.

I'll see if there is a formula that converts the date to Julian Dates. We did this in mainframe programs all the time. When both dates are in Julian Date form, all you need to do is subtract them.

George
Bish99&@ wrote:
Sun Feb 04, 2018 8:11 pm
Thanks George for you help, but when I used this code it returned the wrong number. The difference between 1/21/2018 and 2/03/2018 should be 14 days, this function returned 24. I don't know what the problem is.


PRINT g(2018,1,21) - g(2018,2,3)
DEF g(y,m,d)
m = (m + 9) % 12
y = y - m/10
nd = INT(365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 ) )
RETURN nd
ENDDEF

REM Difference between two dates = g(y2,m2,d2) - g(y1,m1,d1)

Thanks again for you assistance.
Steve
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
rbytes
Posts: 1337
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Help please - date math

Post by rbytes »

I tested Steve's dates in George's formula and also got 24 days difference. Reversing the order of the dates gave me a result of -24.

Once George can correct the calculations, all we need to do is enclose the date subtraction line within an ABS function.

Then it would not matter which date goes first - the result would be the same.
The only thing that gets me down is gravity...

Post Reply