pulling date from the server

Results 1 to 2 of 2

Thread: pulling date from the server

  1. #1
    Join Date
    Dec 1969

    Default pulling date from the server

    I need to pull the date from the server.<BR>My guess is that I need to use the VBScript Date function in ASP to do this, but I can&#039;t seem to figure out how to use it in JavaScript once I get it.<BR>I&#039;m guessing VBScript and JavaScript store dates in different formats. Is there a transform algorithm I can use to convert from one to the other?

  2. #2
    Join Date
    Dec 1969

    Default Excellent analysis!

    The safest way to do it, which will work in all countries, is this:<BR><BR>&#060;SCRIPT Language=JavaScript&#062;<BR>var serverDate = new Date( &#060;%=Year(Date)%&#062;, &#060;%=Month(Date)-1%&#062;, &#060;%=Day(Date)%&#062; );<BR>&#060;/SCRIPT&#062;<BR><BR>The constructor of a Date object allows many forms of date, but whether they will work with the string form you would get from doing &#060;%=Date()%&#062; via VBS depends on where in the world you are, which browser you are running, etc.<BR><BR>But the form <BR> new Date( yr, mn, dy )<BR>is not context-sensitive or locale-sensitive, so it always works. And, similarly, the VBS functions Year(), Month(), and Day() ignore locale and return just the expected numbers.<BR><BR>The only "funny" is that JS month numbers start at zero, whereas COM month numbers start at one.<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