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

Please help in getting milliseconds using asp

Status
Not open for further replies.

millisecond

Programmer
Feb 10, 2003
1
0
0
US
Hi All,
Iam getting problem in retrieving milliseconds using asp programming. My problem is I wanna get the milliseconds from a date(datetime or from any date).Could you please help me out in this problem. In ASP I couldn't find any standard funtions or methods. If you know please send me information to prasadmsc@excite.com.

Thanks
prasad.
 
This has always been an issue for me as well. VB & VBScript's Date datatype does not store milliseconds. What I have done in the past is store the time in the database without the milliseconds or in my SELECT statement, I use a function to chop off the milliseconds before returning it to the VBScript. If you need the milliseconds, this is a problem. If it is only for display purposes, you can convert it to a varchar in the SELECT statement that way it is returned to VBScript as a string. This method is only useful for displaying it. It won't allow you to perform date related functions against it.

If anyone has a better way of dealing with it, I would certainly like to hear it.

Chris.
 
I think you can use Javascript in the source also for this task or a component.
But using both Javascript and Vbscript on same ASP page it will be slow in some way but will work as i knw ________
George, M
 
I didn't think you could use both on the same page. Client-side yes, but server-side I think you are limited to only one or the other. I personally wouldn't want to combine them anyway. Go with one or the other. Just my $.000000002 though.

Chris.
 
>> I didn't think you could use both on the same page

yes you can but there are technical articles on MSDN that explain potential performance problems when doing so.

-pete
 
Yes you can use and actually interact between them using "runat" directive.
Code:
<%@language=VBSCRIPT%>
<%
'asp code here
dim x
x=getTime()
%>
<script language=javascript runat=server>
function getTime()
{
  var tmp=new Date()
  return tmp
}
</script>

But actually you can entirelly write whole asp using
Code:
<script language=vbscript runat=server>
</script>
and
Code:
<script language=javascript runat=server>
</script>

And finally here is an example how can you get hour mins second and millisecond
Code:
<script language=javascript runat=server>
function getTime()
{
	t=new Date()
	var tmp=&quot;&quot;
	tmp+=&quot;Hours:&quot;+t.getHours()
	tmp+=&quot; Minutes:&quot;+t.getMinutes()
	tmp+=&quot; Seconds:&quot;+t.getSeconds()
	tmp+=&quot; Milliseconds:&quot;+t.getMilliseconds()
return tmp
}
</script>
<%
dim time1
time1=getTime()
response.Write &quot;Time1:&quot;&time1
%>

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top