-
Date Problems
I use this command:
DateAdd("d", DateDiff("d", Now, DateAdd("d", somevariable, DateSerial(1900, 1, 1))), Date)
Where "somevariable" is the amount of days after 1900 (given to me by C++). Although using this method for the current amount of days since 1900 (that C++ gives me) I'll end up with a day like 11/22/2002. Any body have any fixes?
-
11/22/2002 is a valid date. What is the problem?
-
It's not today's date. "somevariable" is the current amount of days after 1900, which I'm getting as 37580 from C++.
-
I think your somevariable is wrong because if I enter 365 instead of somevariable I get 1/1/1901 and if I use 730 I get 1/1/1902, both of which seem correct.
-
Hmmm. I think either the VB formula or C++ is not considering leap years. There have been about 25 leap years since 1900 and I think that that is the number of days you are off.
-
It's the C++ thing. I don't think its considering leap years. If you try 1825 (365 * 5) it correctly returns 12/31/1904. Any ideas on how to fix it?
-
DateDiff("d", "1900/1/1", Now)
returns 37605
-
Ok well do you know of any C++ DateDiff like functions. It's because the method being used in the C++ isn't considering leap years. I'm thinking of something like:
int days = (timestruct->tm_year * 365) + timestruct->tm_yday + int(timestruct->tm_year / 4);
if(timestruct->tm_mon < 2 && timestruct->tm_year % 4 == 0) //2 = March
{
days--;
}
-
-
OK, that function should do good enough anyways. Thanks.