Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Set Server date

Author  Topic 

CanadaDBA

583 Posts

Posted - 2004-09-16 : 11:17:18
Env.: Win2000, SQL2000

Is there any command or way to set the server date?

For a testing reason, I have to set our test server's date to older date but the domain controler refreshes the time every 30-40 minutes. Is there a way to stop it or I have to set the date by a running script.

Thanks,

Canada DBA

CanadaDBA

583 Posts

Posted - 2004-09-16 : 14:56:07
I wrote the following code and ran it on the server. It solved my problem.

DECLARE @I INT, @DateString VarChar(255), @D DateTime

WHILE GetDate() < '2004-09-30 00:00:00'
BEGIN
SET @D = DateAdd(minute, 1, GetDate())
WHILE Convert(VarChar(10), GetDate(), 8) < Convert(VarChar(10), @D, 8)
SET @I = 0
IF Month(GetDate()) = 9 AND Year(GetDate()) = 2004
BEGIN
Set @DateString = 'DATE '+Convert(VarChar(10), DateAdd(Day, 3, DateAdd(Month, -3, GetDate())) , 1)
exec @I=master.dbo.xp_cmdshell @DateString
END
END

Note that my need was to change the server time to an older time, i.e. if today is Sep 16, I need it to be Jun 19. Tomorrow, I need to be June 20. and so on...

If you have any modification, post it hear?

Canada DBA
Go to Top of Page
   

- Advertisement -