Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve server time for a particular server

Status
Not open for further replies.

Ankor

Programmer
Mar 21, 2002
144
US
I would like to retrieve server time for a particular machine. I have several web servers in different time zones, but I want them all to lock the submit button on the front-end when my database server updates the records. I know how to do it in JavaScript, but the code will require the customization depending on the time zone. Also, I cannot send server time in the stored procedure.
 
if the servers are serving their own pages in different time zones, you can use a combination of JS and Now() or Time() to set a cut off time, so JS will disable the button if the page is not navigated or disabled, and on navigation or submissions you can disable it server side.

basically, if each server does updates in their local time at say 10pm

if Now() > Cdate(Date() & " 10:00:00 PM") then
OptionDisable = " DISABLE"
Else
OptionDisable = ""
End If


<input type="submit" <%=OptionDisable%> value="Submit">

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
thinking on the fly here.

have a page on the DB server that displays the time when called. Then use the XMLHTTP object on the remotes to grab the text from the page.

Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
forgot to mention, instead of just optiondisable, you could put include files in the conditional instead, that way .. form is displayed OR DB updates maintenance message.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Thank you for your suggestions. I guess I have to explain in details what I need. I have several web servers in different time zones, and one database server that uses EST. Depending on the IP address my users are redirected to the regional web server, but they still use the same database. If the web server uses EST too, I can write JS and it will do the job:
function test(){
var date = new Date();
h = date.getHours();
if (h >= 7 && h <= 8){
document.formname.Submit1.disabled=true;
}
}

If I am on the web server that is two hours behind, my script will have to look differently:
function test(){
var date = new Date();
h = date.getHours();
if (h >= 5 && h <= 6){
document.formname.Submit1.disabled=true;
}
}

In this case it will disable the button when the database server is running the task from 7 to 8 EST. The users cannot access web pages on the other web servers. I was wondering if there any way (object) that can be used to retrieve time from the named server. I basically want to say: here is an IP address of the server that should be used for the time determination, please send me a value :).

I have never used XMLHTTP. Maybe it’s something I should use?

 
ah, easiest haul on this would be to bounce off the EST server for a time, or even javascript..

<script src="
the same code you posted in your reply could be put into this page with the server's time settings, and then the JS would run remotely on that time, not the client's time or the GMT server's time.

and .. if you use XMLHTTP to retrieve it, you could even patch in the above mentioned includes for the different messages on the page or do a redirect etc.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
The XMLHttp object is an option. Can you serve an ASP page from the database server? Or really any web service will work. Just get it to respond with the current date/time of the server. If you can, here's an example for ASP

gettime.asp located on your database server
Code:
<%
Response.Write Now
%>

On your regional web servers. Use the XMLHttp object to request that page and retrieve the results.

For example.
somepage.asp located on a regional server
Code:
<%
dim databaseServerTime
dim myObj
set myObj = Server.CreateObject("Microsoft.XMLHTTP")
myObj.Open "GET", "databaseserver/gettime.asp", False
myObj.Send
databaseServerTime = myObj.ResponseText
myObj.Close
set myObj = Nothing
%>
Now you've got the system date / time from the database server in a variable on your regional web server. You may need to search a little here in the ASP forum to perfect working with this object's methods, status properties, error codes, etc.., but you shouldn't have any problem with this.

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top