Get / set system Date / Time

Setting the PC system Date/time


{Created by Carlos Beguinge, Sept 12, 1993}
{Program to get the systems date using [GetDate] and allowing you to
  change the date using [SetDate]. Feel free to incorporated into any
  other code, and change it as you wish... Enjoy.}
{P.S. Any changes made to make this code better please post it back to me
  outlining the changes, Thank you.}

uses Dos, Crt;

  days : array [0..6] of String[9] = {Array of Weekdays set here}
  y, m, d, dow, I, Code : Word; {Setting the variables here}
  changedt, cch : Char;
  flagd, flagm, flagy : boolean;
  ch : String;

procedure start(Code: Word); Forward; {To allow to go forward in a }
                                             {procedure. Used for Error }
                                             {Checking. }

procedure compute; {Called from procedure Start }
begin {Moves the numeric string to }
  Val(ch, I, Code); {numeric value. then checks }
    if code <> 0 then {for errors. if error true }
    begin {then Call procedure Start }
      Writeln('Error in Date Statement', 'Press any key to Start Again ');
    end; {Else Process Month, Day, and}
    if (flagm = false) then {Year. }
      m := I;
      flagm := true;
      cch :=#0;
    if (flagd = false) and (cch > #0) then
      d := I;
      flagd := true;
      cch :=#0;
    if (flagy = false) and ( cch > #0) then
      y := I;

      flagy := true;
      cch :=#13;
  ch := '';

procedure ResetVars; {Called from procedure Start }
begin {Resets all variable. }
  Code :=0;
  d :=0;
  m :=0;
  y :=0;
  flagd := false;
  flagm := false;
  flagy := false;
  ch :='';
  cch := #0;

procedure start; {Called from Main Program }
  ResetVars; {Calls procedure ResetFields }
  while (cch <> #13) do {Gets input from the keyboard}
    begin {until a "/" or "Enter is }
      cch := readkey; {pressed. }
      while (cch <> #47) and (cch <> #13) do
          ch := ch + cch; {Adds the each numeric charac}
          write(cch); {ter to the string variable }
          cch := readkey;
      compute; {Calls procedure Compute }

begin {Main Program which calls }
  clrscr; {procedure Start }
  Writeln('Today is ', days[dow],', ',
          m:0, '/', d:0, '/', y:0);
  Write('Would you like to change this Date? ');
  if upcase(changedt) ='Y' then
     SetDate(y,m,d); {Sets the Date if Changed }
     Writeln('Today is ', days[dow],', ',
          m:0, '/', d:0, '/', y:0);
     begin {Date remains unchanged }
        Writeln('Today'#39's date Was NOT changed ');
        Writeln('Today is ', days[dow],', ',
           m:0, '/', d:0, '/', y:0);


Share this article!

Follow us!

Find more helpful articles: