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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server Timestamp

Status
Not open for further replies.

lamchop

IS-IT--Management
Nov 4, 2002
6
CA
I need to retrieve the server's timestamp. Specifically, I only need the day of the week and the time (in 24 hr format). How would I do this? I'm unfamiliar with this language so I need a little help on handling it in my HTML page. Can I use this data in a javascript comparison?
 
You can retrieve the date by using the ASP function Now. To pull out only the time you can use the FormatDateTime function with option 4(i think) for short time. Then you can use the WeekDay and WeekDayName functions to pull out the day of week:
Function WeekDay(aDate as Date) as Integer
Function WeekDayName(dayofweek as Integer) as String

Now if you want this data in the javascript all you need to do is output it in the appropriate place (ie, in the javascript rather than in the body), like so:
Code:
<%
Option Explicit

Dim myDate, server_time, server_DOW
myDate = Now
serverTime = FormatDateTime(myDate,4)
serverDOW =  WeekDayName(WeekDay(myDate))
%>
<html>
<head>
<script language=&quot;JavaScript&quot;>
<!--
var serverTime, serverDayOfWeek;
serverTime = &quot;<%=server_time%>&quot;;
serverDayOfWeek = &quot;<%=server_DOW%>&quot;;
//-->
</script>
</head>
<body>
<input type=&quot;button&quot; onClick=&quot;alert('Server Time: '+serverTime+'\nserver day: ' + serverDayOfWeek);&quot;>
</body>
</html>

Hope this helps,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top