#### Topic: How to count an amount of days between two dates?

Long thought, but invented only through a back place in a cycle. And it seems that it is possible to make the artful formula. As it is necessary to count date (day, month, year) through certain amount of days. Google did not find any algorithms.

#### Re: How to count an amount of days between two dates?

Hello, Submitter, you wrote: S> Long thought, but invented only through a back place in a cycle. And it seems that it is possible to make the artful formula. To translate both dates in seconds (*), a difference to translate in days. S> as it is necessary to count date (day, month, year) through certain amount of days. Initial date to translate in seconds, to add necessary number of days in the seconds, the received value to translate in date (*) (*) Translation functions of "human" date in seconds and reversely depend on used language and system. For example: GetSystemTime, SystemTimeToFileTime

#### Re: How to count an amount of days between two dates?

Hello, Submitter, you wrote: S> Long thought, but invented only through a back place in a cycle. And it seems that it is possible to make the artful formula. S> as it is necessary to count date (day, month, year) through certain amount of days. S> Google did not find any algorithms. To translate in time_t well or in something there in seconds from basic date, to count a difference and to divide into number of seconds in days

#### Re: How to count an amount of days between two dates?

Hello, Submitter, you wrote: S> Long thought, but invented only through a back place in a cycle. And it seems that it is possible to make the artful formula. S> as it is necessary to count date (day, month, year) through certain amount of days. S> Google did not find any algorithms. Date in computers always expresses in any units (seconds, days, 100 intervals...) from any fixed date. It is necessary to learn an amount of these units in days and to divide into it a difference in units of these two dates.

#### Re: How to count an amount of days between two dates?

Hello, Submitter, you wrote: S> Long thought, but invented only through a back place in a cycle. And it seems that it is possible to make the artful formula. S> as it is necessary to count date (day, month, year) through certain amount of days. S> Google did not find any algorithms. Well here the ready. A difference in time_t you divide on 86400.

#### Re: How to count an amount of days between two dates?

Hello, Submitter, you wrote: S> Long thought, but invented only through a back place in a cycle. And it seems that it is possible to make the artful formula. S> as it is necessary to count date (day, month, year) through certain amount of days. S> Google did not find any algorithms. The textbook of astronomy is necessary to you, instead of Google. int encodeDate (int Year, int Month, int Day) {int c, ya; if (Month> 2) Month - = 3; else {Month + = 9; Year-;} c =Year/100; ya=Year-100*c; c = (146097*c)/4 + (1461*ya)/4 + (153*Month+2)/5 + Day + 1721119; return c;} void decodeDate (int date, int &Year,int &Month,int &Day) {date - = 1721119; Year = (4*date-1)/146097; Day = (4*date-1-146097*Year)/4; date = (4*Day+3)/1461; Day = (4*Day+7-1461*date)/4; Month = (5*Day-3)/153; Day = (5*Day+2-153*Month)/5; Year = 100*Year + date; if (Month <10) Month + = 3; else {Month - = 9; Year ++;} }...//1 - it is possible to make the artful formula int days=encodeDate (2010,1,1)-encodeDate (2000,1,1);//2 - to count date (day, month, year) through certain amount of days int d1=encodeDate (2000,1,1); int d2=d1+days; int y, m, d; decodeDate (d2, y, m, d);

#### Re: How to count an amount of days between two dates?

Hello, Submitter, you wrote: S> Long thought, but invented only through a back place in a cycle. And it seems that it is possible to make the artful formula. S> as it is necessary to count date (day, month, year) through certain amount of days. S> Google did not find any algorithms. QDate dt1 = QDate (12, 12, 2000); QDate dt2 = QDate (12, 12, 2001); int diff = dt2.toJulianDay () - dt1.toJulianDay ();

#### Re: How to count an amount of days between two dates?

Hello, Kodt, you wrote: Hello, kov_serg, you wrote: _>> the Textbook of astronomy is necessary to you, instead of Google. _>> int encodeDate (int Year, int Month, int Day) {_>> c = (146097*c)/4 + (1461*ya)/4 + (153*Month+2)/5 + Day + 1721119; _>>} _>> void decodeDate (int date, int &Year,int &Month,int &Day) {_>> date - = 1721119; _>>} 1721119 days are Christmas, from World Creation? This offset on what especially does not influence... 1721119 is the offset from JD 0 to the start of March 1BC (since there was no 0AD); subtracting this gives the number of days since then...

#### Re: How to count an amount of days between two dates?

Hello, kov_serg, you wrote: _> c = (146097*c)/4 + (1461*ya)/4 + (153*Month+2)/5 + Day + 1721119; _>... _> date - = 1721119; What for at first  and then to take away this constant?

#### Re: How to count an amount of days between two dates?

Hello, alex_mah, you wrote: _> Hello, kov_serg, you wrote: _>> c = (146097*c)/4 + (1461*ya)/4 + (153*Month+2)/5 + Day + 1721119; _>>... _>> date - = 1721119; _> What for at first  and then to take away this constant? That on %7 would give day of week. And if there will be a negative number that rounding off will work not so, and the result will be not true. And so on these numbers it is possible and . And as popular wisdom states: "works. Not "

#### Re: How to count an amount of days between two dates?

Hello, Submitter, you wrote: S> Long thought, but invented only through a back place in a cycle. And it seems that it is possible to make the artful formula. S> as it is necessary to count date (day, month, year) through certain amount of days. S> Google did not find any algorithms. It is necessary to take ready library, calendars - a thing difficult. Here some facts: - in days not always 24 hours - in a year not always 365 days (well it is all know) - in a minute not always 60 seconds Was specific on questions: - in days it is considered as a difference unix timestamp two dates  on duration of day in seconds with a rounding off to the nearest whole - "to add day to current date", "to subtract day from current date", to translate current date in unix/UTC timestamp is the library or API should do.

#### Re: How to count an amount of days between two dates?

Hello, alex_mah, you wrote: _> Hello, kov_serg, you wrote: _>> c = (146097*c)/4 + (1461*ya)/4 + (153*Month+2)/5 + Day + 1721119; _>>... _>> date - = 1721119; _> What for at first  and then to take away this constant? It generally in two different functions happens. For a minute

#### Re: How to count an amount of days between two dates?

Hello, scf, you wrote: scf> It is necessary to take ready library, calendars - a thing difficult. Here some facts: scf> - in days not always 24 hours scf> - in a year not always 365 days (well it is all know) scf> - in a minute not always 60 seconds Everything, except the second point, does not concern the given task. The third does not influence at the standard account through unixtime or time Windows. The first is not essential, if all to consider across Greenwich.

#### Re: How to count an amount of days between two dates?

Hello, Kodt, you wrote:>> 1721119 days are Christmas, from World Creation? _>> this offset on what especially does not influence Clearly that on what does not influence, and here about julian day 0 did not know, interesting. There generally these canons, what day zero, a little. Normally implement one the most widespread.

#### Re: How to count an amount of days between two dates?

Hello, netch80, you wrote: N> Hello, alex_mah, you wrote: _>> Hello, kov_serg, you wrote: _>>> c = (146097*c)/4 + (1461*ya)/4 + (153*Month+2)/5 + Day + 1721119; _>>>... _>>> date - = 1721119; _>> What for at first  and then to take away this constant? N> it generally in two different functions happens. For a minute Also what? One encodes, another decodes. But here would explain _> more low That on %7 gave day of week.

#### Re: How to count an amount of days between two dates?

Hello, alex_mah, you wrote: _>>> Hello, kov_serg, you wrote: _>>>> c = (146097*c)/4 + (1461*ya)/4 + (153*Month+2)/5 + Day + 1721119; _>>>>... _>>>> date - = 1721119; _>>> What for at first  and then to take away this constant? N>> it generally in two different functions happens. For a minute _> Also what? _> One encodes, another decodes. _> but here would explain _>> more low That on %7 gave day of week. No, not therefore. If business was only in it, such big  it would be not necessary - all other items give nonnegative values. Would be values from 0 to 6 enough to quit into our account of days of week. The constant 1721119 grows from Julian day and shows offset to a reference point of this scale.