Set the server date | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Set the server date

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, CanadaDBA
Did you change time in W2000?
Luis Martin
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.
I changed the time on the machine but it goes back to today by the domain controller after 30 or 40 minutes. I want to disable this feature or write a script and run it on the server to set it to the date that I want whenever it is changed to today.
quote:Originally posted by LuisMartin Did you change time in W2000?
Luis Martin
Moderator

CanadaDBA
You can set the time with the DOS command TIME, you could do this from SQL using xp_cmdshell, you could append the time you want to set it to using dynamic sql. to stop it resetting on the server, disable the Windows Time service, I think. Tom Pullen
DBA, Oxfam GB
If you’re on a w2k3 domain, just beware that it will screw up Kerberos authentication… also if you have SMS or other sunch management type servers, these can get up set if the time is not in synch Cheers
Twan
Thank you for the dynamic sql suggestion. It can solve my problem. Regarding disable windows time service, do you mean that it disables the domain time synchronizing? Do you remember how to do that?
quote:Originally posted by thomas …to stop it resetting on the server, disable the Windows Time service, I think. Tom Pullen
DBA, Oxfam GB

CanadaDBA
Thank you for the information, Twan. I don’t know about these. Do you think if I reset the server’s date periodically (every 30 minutes) it may affect something?
quote:Originally posted by Twan If you’re on a w2k3 domain, just beware that it will screw up Kerberos authentication… also if you have SMS or other sunch management type servers, these can get up set if the time is not in synch Cheers
Twan

CanadaDBA
I wrote the following code and ran it on the server. Thank you Thomas for your suggestion. It solved my problem. <br /><pre><br />DECLARE @I INT, @DateString VarChar(255), @D DateTime<br /><br />WHILE GetDate() &lt; ‘2004-09-30 00:00:00′<br />BEGIN<br /> SET @D = DateAdd(minute, 1, GetDate())<br /> WHILE Convert(VarChar(10), GetDate(), <img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ /> &lt; Convert(VarChar(10), @D, <img src=’/community/emoticons/emotion-11.gif’ alt=’8)’ /> <br /> SET @I = 0 <br /> IF Month(GetDate()) = 9 AND Year(GetDate()) = 2004 <br /> BEGIN<br /> Set @DateString = ‘DATE ‘+Convert(VarChar(10), DateAdd(Day, 3, DateAdd(Month, -3, GetDate())) , 1) <br /> exec @I=master.dbo.xp_cmdshell @DateString<br /> END<br />END<br /></pre><br />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…<br /><br />If you have any modification, post it here.<br /><br />CanadaDBA
Make sure you talk to the network people about this if you decide to mess with the server time. If you don’t, you could incur some serious wrath. MeanOldDBA
[email protected] When life gives you a lemon, fire the DBA.
Although it is a pre-production server and we just use it as test server, but it’s good idea and I will let them know. Thanks
quote:Originally posted by derrickleggett Make sure you talk to the network people about this if you decide to mess with the server time. If you don’t, you could incur some serious wrath. MeanOldDBA
[email protected] When life gives you a lemon, fire the DBA.

CanadaDBA
]]>