The current date and time from the server not the

Results 1 to 6 of 6

Thread: The current date and time from the server not the

  1. #1
    Join Date
    Dec 1969
    Posts
    15

    Default The current date and time from the server not the

    Hello! Looking to have a server side script instead of client side which will get the current date and time. <BR> <BR>Is it a correct assumption to make that if use the getHours and getMinutes methods of the Date object then the server time will be the one used for time calculations on the page? The goal is to redirect from a form page from 3:00 A.M. ET Saturday morning through Sunday night at midnight. The users are in various time zones and the server is located in the Midwest in central time. <BR> <BR>The form should not be used for input for most of the weekend and will redirect to a page indicating this fact if the server time is within the range defined previously. Realize that some calculations will be needed to determine the east and west times since the server is in the central time zone. <BR> <BR>If the server side script assumption is correct and the time can be retrieved then does the redirect, would probably use location.href = redirectpage.html, need to be on the server side script or can it be in the client and checked versus values passed back from the server script to the client? Hope the above was worded correctly. <BR> <BR>If anyone knows of any scripts that might do this somewhere that would be appreciated very much. Would appreciate any responses or recommendations at your convenience. Thanks! <BR> <BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    96,118

    Default Write server side script...

    If you code:<BR><BR>&#060;SCRIPT Language=JavaScript&#062;<BR>var theTime = new Date();<BR>&#060;/SCRIPT&#062;<BR><BR>then theTime is the time on the user&#039;s machine.<BR><BR>If you code *EITHER* of these:<BR><BR>&#060;SCRIPT Language=JavaScript RUNAT="SERVER"&#062;<BR>var theTime = new Date();<BR>&#060;/SCRIPT&#062;<BR><BR>** OR **<BR>&#060;%@ Language="JScript" %&#062;<BR>&#060;%<BR>var theTime = new Date();<BR>%&#062;<BR><BR>then theTime is the date and time on the server.<BR><BR>*********************************** ************************<BR><BR>&#062; location.href = redirectpage.html<BR><BR>That *only* works on the client. "location" is a *BROWSER* object (an object subordinate to the "window" object, in fact). That object doesn&#039;t even exist on the server.<BR><BR>If you want redirection to occur on the server, you would write:<BR><BR>&#060;%<BR>Response.Redirect( "xyz.html" );<BR>%&#062;<BR><BR>or similar. <BR><BR>If you are going to use server-side JScript, maybe you should get a good book on ASP and learn what it is capable of? And what the differences between server and client code are. Just because they can share the same language doesn&#039;t mean they share anything else, including the fundamental DOM objects of the browser.<BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    15

    Default RE: Write server side script...

    Hey Bill! Thanks for the great information it really helped. <BR> <BR>Got some samples working. Was trying to do one more thing which was more for testing purposes than anything but was wanting to put out an alert box on the first page before the redirect to the second page. <BR> <BR>The code used was as follows. <BR>&#060;% alert("This is a test") %&#062; but this results in an error on the page. Is the alert function one of those objects not supported or is it just not correct? Have a copy of the Mastering Javascript and Jscript book which has a few examples of an asp page with javascript but the alert was not used anywhere in the sample pages. <BR> <BR>Very much appreciate the great help so far. Thanks! <BR> <BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    1,424

    Default RE: Write server side script...

    Problem is you are trying to do an alert on the Server.<BR><BR>Think about it... whatever appears between &lt;% and %&gt; is evaluated on the Server, then sent to the client.<BR><BR>What you need to do is...<BR><BR>&lt;% <BR>Response.Write ("alert(""This is a test"") ;" ) ;<BR>%&gt;


  5. #5
    Join Date
    Dec 1969
    Posts
    96,118

    Default Nod, nod...and more...

    Think about it: If you *could* use server-side script to pop up an alert, WHERE would it pop up????<BR><BR>Why on the system console of the server!<BR><BR>I&#039;d be that the system administrator of your web server would shut down your ASP pages awful darned fast after he got 237 popups on his screen in 13 minutes!<BR><BR>

  6. #6
    Join Date
    Dec 1969
    Posts
    15

    Default RE: Nod, nod...and more...

    Hey! Yeah that makes a lot of sense and should have known that. Guess it was getting kind of late but you guys were up even later. <BR> <BR>The help has been great and have a good handle on ways to set up this functionality now. Thanks! <BR> <BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •