Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

date change

Posted on 2004-04-26
4
Medium Priority
?
204 Views
Last Modified: 2010-04-05
Hey,
I have a little problem with my program, it should change the date to (somedate) run a program, wait 5s and change it back.

Tom

--snip--

procedure TForm1.FormCreate(Sender: TObject);
var
myDate,newDate : TDateTime;
myYear, myMonth, myDay : Word;
begin
DecodeDate(myDate, myYear, myMonth, myDay);
myDate := StrToDate('04/24/2003');
WinExec('c:\bin\date', SW_SHOWNORMAL);
Sleep(5000);
newDate := EncodeDate(myYear, myMonth, myDay);
ReplaceDate(myDate, newDate);

//myDate := RecodeDate(myDate, myYear, myMonth, myDay);
Application.Terminate;

end;
0
Comment
Question by:T0masz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10920853

   You do not replace the system date ...

   use the API SetLocalTime

   example :

procedure TForm1.Button1Click(Sender: TObject);
var
  SysTime : TSystemTime;
begin
  with SysTime do
    begin
      wYear         := 2004;
      wMonth        := 4;
      wDayOfWeek    := 3;
      wDay          := 4;
      wHour         := 20;
      wMinute       := 51;
      wSecond       := 0;
      wMilliseconds := 0;
    end;
  SetLocalTime(SysTime);
end;
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10920893

  use can use also this function to convert TDateTime to TSystemTime and back

  function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 2000 total points
ID: 10920962
An example:

procedure TForm1.FormCreate(Sender: TObject);
var  myOldDate, myDate:   TDateTime;
     dwMark:              LongWord;
     sysTime:             SYSTEMTIME;
begin

  // Persist the current date
  dwMark:=GetTickCount;
  myOldDate:=Now;

  // Example date setting
  myDate:=StrToDate('04/24/2003');

  // Decode the date (use the current time)
  with sysTime do
  begin
     DecodeDate(myDate, wYear, wMonth, wDay);
     DecodeTime(myOldDate, wHour, wMinute, wSecond, wMilliseconds);
  end;

  // Set the time
  SetLocalTime(sysTime);

  // Do whatever
  // WinExec('c:\bin\date', SW_SHOWNORMAL);
  Sleep(5000);

  // Update with the number of milliseconds that we were delayed
  dwMark:=GetTickCount-dwMark;
  myOldDate:=myOldDate+(dwMark / MSecsPerDay);

  // Reset the date time
  with SysTime do
  begin
     DecodeDate(myOldDate, wYear, wMonth, wDay);
     DecodeTime(myOldDate, wHour, wMinute, wSecond, wMilliseconds);
  end;

  // Set the time
  SetLocalTime(sysTime);

  // Finished
  // Application.Terminate;

end;

The dwMark variable (seeded with GetTickCount) is used for keeping track of how many ms elapsed while the time was changed.

Hope this helps,
Russell

0
 

Author Comment

by:T0masz
ID: 10921181
Thanks to all of you, but rllibby was the closest one, plus I really dont like using TSystemTime because you have to put all the parameters date,time so on and on one station it didnt work correctly for some reason.

Tom
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question