LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

How to get different between two dimes/dates?

Root / Programming Questions / [.]

joelableCreated:
I'd like to know if there is a simple way to do this, like get the time difference between 12:34 and 14:12 and even between dates. If someone has an algorithm for this then please help.

I would approach this by converting the times to seconds, then performing subtraction, then converting back to hours and minutes. Date calculations are trickier, but a similar principle: convert your dates into days and then back again. Use a fixed point of reference, such as 01/01/2000, to be the "beginning of time" where day=0. Store your dates internally as integers signifying the number of days since the beginning of time. Once you've got it working then add support for leap years :-)

How I would approach it is this: For time, I couldn't say it much better than ezman. For dates, I would approach it thusly: Find the distance between the years, months, and days. So between 9/8/13 and 3/4/14: 3-9=-6, 4-8=-4, and 14-13=1. Then, multiply the respective time measure by it's value in days. -6*(365/12)=-183 (rounded up for most accurate measure). -4*1=-4, and 1*365=365. Then add these values. -183-4+365=178. Thus the distance is 178 days. This should be fairly accurate, the only possible problem being the months working based off of fair distribution of all days between all months, and that's not always accurate (why though, February? Why?) The value of months should always be rounded.

You're looking for TMREAD and DTREAD. DTREAD DATE$ OUT Y,M,D TMREAD TIME$ OUT H,M,S ctrl+f tmread here http://smilebasic.com/en/reference/

okay, thanks guys :)

Of course, using the integer data type to store seconds after 2000, you will run into 'Y2K' in 2068. Just sayin'.

i dont think ill be using my programs in 2068 lol

Mariominer, I like your approach to the date issue: it's nice and simple, and accurate enough for a lot of purposes. What about using your method, but with the addition of a month's array, which is a lookup for the number of days in each month, but cumulative, so that each entry in the array returns the number of days between January 1st and the beginning of that month? Eg. DIM M[13] M[0]=0 'not used M[1]=0 M[2]=31 M[3]=59 ...etc... Then, in your calculation, the month can be converted into days via a simple array lookup to make it more accurate.

I like that solution to the month issue. Good work around versus estimation, which could make times vary for month swaps.

http://petitcomputer.wikia.com/wiki/How_to_get_the_number_of_days_between_dates The most important part is the leap year system. I know this tutorial is for days, but you can convert it to calculate the number of seconds since 2000 rather than the days since 2000 using the same method. I can write up a thing at the bottom sometime about doing seconds instead of days (if I have time)