home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TPDB21.ZIP / DATEDEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-02-22  |  2.1 KB  |  71 lines

  1. {$A+,B+,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}
  2. {$M 65520,0,655360}
  3. Program DateDemo;
  4.  
  5. Uses CRT,TPDB,TPDBDate;
  6.  
  7. {Demonstration of date handling functions.}
  8.  
  9. {Field  Field Name  Type       Width    Dec
  10.       1  DATE1       Date           8
  11.       2  DATE2       Date           8
  12.       3  DATE3       Date           8
  13.  ** Total **                      25}
  14.  
  15.  
  16. { Function CalcDate(InDate:DateStr;Days,Months,Years: integer): DateStr;
  17. (* Add or subtract days,months, or years from two dates. *)
  18.  
  19. Function CDOW(InDate : DateStr): DayStr;
  20. (* Returns character day of week - i.e. 'Monday','Tuesday',etc. *)
  21.  
  22. Function CMonth(InDate : DateStr) : Str9;
  23. (* Returns character month - i.e. 'March' *)
  24.  
  25. Function CompDates(Date1,Date2 : DateStr):Word;
  26. (* Compares two dates and calculates the number of days between them. *)
  27.  
  28. Function CTOD(InDate: DateStr) : DateType;
  29. (* Converts a .DBF compatible date field to a word date type. *)
  30.  
  31. Function DTOC(Julian: DateType) : DateStr;
  32. (* Converts a word date type to a string compatible with .DBF date fields. *)
  33.  
  34.  
  35. Function Mon(InDate : DateStr) : Byte;
  36. (* Returns numeric value for the month in a date. *)
  37.  
  38. Function TimeNow : TimeStr;
  39. (* Returns current time in formatted string. *)
  40.  
  41. Function Today : DateStr;
  42. (* Returns current date in .DBF date field compatible format. *)
  43.  
  44. Function ValidDate(InDate : DateStr): boolean;
  45. (* Checks whether a date is valid. *)}
  46. Var
  47.     Number : String;
  48.     Num : word;
  49.  
  50.  
  51. begin
  52.     ClrScr;
  53.     DBOpenFile('datedemo.dbf');
  54.     GetDBRec(1);
  55.     Display;
  56.     Num := CompDates(FieldToStr(1),FieldToStr(2));
  57.     Str(Num:5,Number);
  58.     Writeln('There are ',Number,' days between Date1 and Date2.');
  59.     Writeln('Date1 was a ',RTrim(CDOW(FieldToStr(1))),'.');
  60.     Writeln('The month of Date2 was ',CMonth(FieldToStr(2)),'.');
  61.     Writeln('Date2 plus 1000 days is ',FormDate(CalcDate(FieldToStr(2),1000,0,0)),'.');
  62.     Repl(3,CalcDate(FieldToStr(2),1000,0,0));
  63.     If not ValidDate('19890229') then
  64.         Writeln('February 29, 1989 is not a valid date.');
  65.     Writeln('Today''s date is ',FormDate(Today));
  66.     Writeln('The current time is ',TimeNow,'.');
  67.     PutDBRec(1);
  68.     CloseDBFile;
  69.     Wait;
  70.     ClrScr;
  71. end.