home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / 30TURUTL / DATETIME.PAS < prev    next >
Pascal/Delphi Source File  |  1985-02-18  |  2KB  |  87 lines

  1. {*
  2.  
  3.                                   Datetime.prg
  4.                                   ------------
  5.  
  6.      Turbo pascal does not have date or time functions as BASIC (DATE$ TIME$)
  7. in many business programs it is necessary to have at least the date , the time
  8. is also very useful in all sorts of programs.
  9.  
  10. I have written here both date and time functions you can use in any of your
  11. Turbo pascal programs either by using the I compiler directive for include ,
  12. for example [$I datetime.prg], or by writing the functions in your programs.
  13.  
  14. try this sample program.
  15.     program sample;
  16.     [$I datetime.prg]         (change '[' to '{' .)
  17.     begin
  18.       writeln;
  19.       write('The date is ',date,' and the time is ',time);
  20.     end.
  21.  
  22.  
  23. Writen  by                     Pinchas Gubits
  24.                                4016 18th Ave.
  25.                                Brooklyn NY 11218
  26.  
  27.                                                                              *}
  28. program datetime;
  29. type
  30. sd = string[10];
  31. st = string[8];
  32.  
  33. function date : sd;
  34. type
  35.   registors = record
  36.               ax,bx,cx,dx,bp,si,ds,es,flags: integer;
  37.               end;
  38. var
  39.   regisrec    : registors;
  40.   month , day : string[2];
  41.   year        : string[4];
  42.   cx , dx     : integer;
  43. begin
  44.   with regisrec do
  45.   begin
  46.     ax := $2A shl 8;
  47.   end;
  48.   msdos(regisrec);
  49.   with regisrec do
  50.   begin
  51.     str(cx , year);
  52.     str(dx mod 256 , day);
  53.     str(dx shr 8 , month);
  54.   end;
  55.   if length(month) = 1 then insert(' ',month,1);
  56.   if length(day  ) = 1 then insert('0',day,1  );
  57.   date := month + '-' + day + '-' + year;
  58. end;
  59.  
  60. function time : st;
  61. type
  62.   registors = record
  63.               ax,bx,cx,dx,bp,si,ds,es,flags: integer;
  64.               end;
  65. var
  66.   regisrec               : registors;
  67.   hour , minute , second : string[2];
  68.   cx , dx                : integer;
  69. begin
  70.   with regisrec do
  71.   begin
  72.     ax := $2C shl 8;
  73.   end;
  74.   msdos(regisrec);
  75.   with regisrec do
  76.   begin
  77.     str(cx shr 8 , hour);
  78.     str(cx mod 256 , minute);
  79.     str(dx shr 8 , second);
  80.   end;
  81.   if length(hour  ) = 1 then insert(' ',hour  ,1);
  82.   if length(minute) = 1 then insert('0',minute,1);
  83.   if length(second) = 1 then insert('0',second,1);
  84.   time := hour + ':' + minute + ':' + second
  85. end;
  86.  
  87.