?
Solved

date change

Posted on 2004-04-26
4
Medium Priority
?
202 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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