DateDiff/DateAdd functions

Blitz3D Forums/Blitz3D Programming/DateDiff/DateAdd functions

Graythe(Posted 2005) [#1]
DateAdd and DateDiff, - Is it possible to call those functions from Blitz?


Graythe(Posted 2005) [#2]
*bump*


Farflame(Posted 2005) [#3]
I'd be interested in this aswell. I managed to write my own functions for this, but they're not very good and I'd like to see some better ones. Where did you see these?


big10p(Posted 2005) [#4]
Are these win32 functions, or something? What do they do?


KuRiX(Posted 2005) [#5]
I suspect you can know the difference between a date and you can add days to a date respectively. I have used something similar in c++.

Perhaps you can wrap them from c++, it is easy.


tonyg(Posted 2005) [#6]
I *think* they're VB functions.
datadd


octothorpe(Posted 2005) [#7]
I believe you'd need to use a userlib to call those functions.

If you have to start from scratch, a great method I'd like to recommend is the "epoch" approach - keep track of dates as the number of seconds which have elapsed since Jan 1, 1970. You only need routines to convert epoch time to human readable and vice versa (I'd use a Type with fields for year, month, day, hour, minute, second), diffing and adding become simple mathematical expressions.

The main drawback of using epoch dates is that they can't describe dates before 1970 or after 2038 (unsigned ints aren't big enough to hold anything larger.)

P.S. don't forget to get your leap years correct! I've seen too many date functions which don't respect all the leap year rules. IIRC: !(y%4) && !!(y%100) && !(y%400)


Graythe(Posted 2005) [#8]
These functions are what I've always used with VB/VBA. I believe that SQL and Access users have very similar, if not identical, functions.

DateDiff can measure the difference between 2 dates and returns a value representing seconds, minutes, hours etc.

DateAdd, when given a string date and a number representing the number of seconds, minutes or hours to add/subtract will return the resultant date.

The range of useable dates is limited to a finite span of approx 68 years at second accuracy. Calculation of dates before and after the bounds must either lose accuracy (use minutes instead of seconds) or be performed using recursive techniques (adjusting the reference date) to avoid an overflow and then performing addition or subtraction by a bit of good old fashioned string processing.

Back in VB3 I'm sure that they were only accessible if an external file was included in the project but can't remember which file (blast my antiquated brain cells). In VB6/VC they're either native or at least apparently seamless.

Some years ago I checked them for centennial (often wrongly called millennial) compliance when that was all the rage and found them to be sound and capable of accurately returning dates within leap years after the 2k boundry - which rather made me wonder what all that fuss was actually about - I later learned that nearly all comliance issues arose from poorly constructed Excel spreadsheets and not just a little bloody mindedness on the part of M$, who stood to gain the most after all the shouting).

So, any help for the Klingons?


Graythe(Posted 2005) [#9]
Actually, I think it's MSAFINX.DLL. My brain might have recovered a lost allocation unit...