Board index » delphi » Number of days between two dates?
James Stuart
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
|
James Stuart
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Number of days between two dates?
I would like to calculate the number of days between two dates.
The dates is from 1990 and on. Are there any units/code already written? JS |
evil d'luse
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Number of days between two dates?here're informations.. 31 28 31 30 31 30 31 31 30 31 30 31 and, remember, 4 years can be count as 1461 days. QuoteJames Stuart <james...@hotmail.com> wrote in message Quote> I would like to calculate the number of days between two dates. |
José Santo
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Number of days between two dates?Quote>I would like to calculate the number of days between two dates. ability to know what's the day of the week for a particular date. I'm pasting it. --------------------------------------------------------------------------- Interface Type TDate=Record Const Function Bissext(Year: TSmallInteger): Boolean; Implementation Function Bissext(Year: TSmallInteger): Boolean; Function DaysInMonth(Year, Month: TSmallInteger): TLongInteger; Function DaysFromYearXToY(YearX, YearY: TSmallInteger): TLongInteger; Function DaysFromMonthXToY(Year, MonthX, MonthY: TSmallInteger): Function DaysFromDateXToY(DateX, DateY: TDate): TLongInteger; Function DayOfWeek(Date: TDate): TSmallInteger; Begin --------------------------------------------------------------------------- You can also easily do a calendar with this unit.But avoid using DayOfWeek Hope this is useful. Regards, Jose Santos |
PiotrC
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Number of days between two dates?QuoteJames Stuart wrote: They use it instead of a "normal" date (day, month, year). JD is the number of days since 1st January 4712 B.C. Having a procedure converting "normal" dates to JD and reverse makes your problem easy to solve. If you like, download my very old program containing such a procedure (RokMD, DataJD). Unfortunately (for you) it's commented in Polish. But look for these two procedure (RokMD and DataJD) and I think you'll understand how to use them. A program calculating the position of Sun and Moon Other programs: Sun and Moon: when do they rise and set (DOS): Sun and Moon: when do they rise and set (Windows 9x), Calendars (Windows 9x, Polish version): PF |
Osmo Ronkan
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Number of days between two dates?QuoteIn article <7tq92f$qp...@zeus.polsl.gliwice.pl>, PiotrCF <P...@who.net> wrote: dependent on time zone. In fact one does not have to care what base one uses. Function Mul365(x:word):longint; Function Div365(x:longint):word; const Dbfmlut:array[boolean,1..12] of word= Function DateNro(y,m,d:integer):longint; {$b-} m:=word(dl) div 32+1; Function WeekDay(nro:longint):word; { 0: Su, 6: Sa } Osmo |
Mike Monet
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Number of days between two dates?QuotePiotrCF wrote: Quote> A program calculating the position of Sun and Moon Thank You! These are going to be very useful. Best Regards, Michael R. Monett |
Dr John Stockto
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Number of days between two dates?JRS: In article <7tq92f$qp...@zeus.polsl.gliwice.pl> of Sun, 10 Oct 1999 16:49:42 in news:comp.lang.pascal.borland, PiotrCF <P...@who.net> wrote: Quote
4713 (4713 sic) BC. IMHO it is better to use Modified Julian Date, MJD = JD-2400000.5, to avoid this, and to make the numbers smaller (pretend you're at Greenwich). <URL: http://www.merlyn.demon.co.uk/programs/dateprox.pas> has code; The routines are sufficiently fast; but since they are programmed from -- |
PiotrC
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Number of days between two dates?QuoteDr John Stockton wrote: Quote>IMHO it is better to use Modified Julian Date, MJD Most computers don't have problems dealing with numbers like 2500000. Quote
but they work and are very short. Take a look at them: Converting "normal" date to JD (r: year, m: month, d: day): var dt: integer; {a global variable: day of week } function DataJD(r,m,d:real):real; An auxiliary function (sorry, I don't remember the reason FUNCTION Int1(x:REAL):REAL; Converting a JD to (year, month, day, hour): PROCEDURE RokMD(jd: REAL; VAR r,m,d:INTEGER; VAR gr:REAL); Regards |
Dr John Stockto
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Number of days between two dates?JRS: In article <7tt1sq$9n...@zeus.polsl.gliwice.pl> of Mon, 11 Oct 1999 18:05:17 in news:comp.lang.pascal.borland, PiotrCF <P...@who.net> wrote: Quote>Dr John Stockton wrote: that in practice the use of MJD is common. Certainly my colleagues used it. But it is a matter of opinion. MJD has the advantage that there were no "funnies" in the calendar (in most "Christian" countries bar Russia) between then and now. Quote>><URL: http://www.merlyn.demon.co.uk/programs/dateprox.pas> has code; problem & I prefer an integer solution. Nowadays the FPU of a PC is fast; but it's unlikely to make much difference to the overall speed. I think I still understand my code, and I recall no outstanding comments from anyone who cannot! There are many ways of getting the right answer. Quote>An auxiliary function (sorry, I don't remember the reason infinity and the standard function truncates towards zero. There is a similar annoyance with MOD & DIV. In longcalc.pas, the MOD & DIV operators are rationally defined across zero, and code using them is simpler. -- |
1. How to get number of days between two date fields
2. HOW 2: Count days between two dates
3. how to get days bw{*word*249} two date?
4. Calculating nbr of days between two DATE fields
5. Number of days between 2 dates
6. Number of days between dates
7. Calculating number of days between 2 dates
8. Dates : Changing day numbers
9. How can I compare two dates in two different coloumns in SQL with ADO components
10. Two more days...