Solved

date change

Posted on 2004-04-26
4
196 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
  • 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 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 137
Dev Express grid collapse 2 34
Find and Replace Stream with 0s 8 48
Base1 Encode/Decode 3 34
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now