• Status: Solved
• Priority: Medium
• Security: Public
• Views: 328

# diff between time and date?

Can i find the difference between two time variables generated by now(). What is the easiest way to do that?
0
rav_chow
• 6
• 4
• 3
• +2
1 Solution

Commented:
Use DateDiff() function:

Description:
Returns the number of intervals between two dates.
Syntax:
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])

Erez Sh.
0

Commented:
interval:
Required. String expression that is the interval you want to use to calculate the differences between date1 and date2.

date1, date2: Required. Date expressions. Two dates you want to use in the calculation.

firstdayofweek: Optional. Constant that specifies the day of the week. If not specified, Sunday is assumed. See Settings section for values.

firstweekofyear: Optional. Constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. See Settings section for values.

The interval argument can have the following values:
Setting - Description
yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second

0

Commented:
i agree with erezsh.

Interval = the time interval to find (month, week, second, etc)

date1= a date (your first Now )
date2= another date (your second Now )

and the other two values are optional and shouldn't be changed unless you need to know specific day/year stuff.
0

Author Commented:
friends, I asked for time.. ie. hour ,min ..
0

Commented:
You asked for date and time and erezsh kindly gave you both.
0

Commented:
Now

The Now function returns the date and time as determined by your computer.

Code:
<% =Now %>

Output:
07/17/2001 10:36:12

If you want to get the diff on time, you will need to create seperate functions to retrieve each value;

dh = DateDiff(h, Now(), (Now()-4))

Response.Write dh
0

Author Commented:
Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'DateDiff'

this is the error is get when i try datediff
0

Commented:
To get the differeces between two dates (and times) in minutes, for example, use:
MinDiff = DateDiff("n", date1, date2)

btw 10x for the support ;)
Erez Sh.

0

Commented:
Maybe you should go to the DevGuru web site and read up on the function DateDiff().
0

Author Commented:
Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'DateDiff'

this is the error is get when i try datediff
0

Commented:
Give me the entire code that you are using so I can tell you what's wrong.
0

Commented:
Here is a full code that tell you how long ago was the 24/6/2001 in says:

<HTML>
<BODY>
<%
date1= now
date2= #24/6/2001#
DayDiff = DateDiff("d",date1,date2)
response.write DayDiff
%>
</BODY>
</HTML>

It works. If it doesn't work for you, then your server has a problem.

Erez Sh.
0

Commented:
You do have IIS installed don't you?
0

Commented:
(in days)
0

Commented:
This tells you exactly in hours, the difference betweeen Now annd 4 days ago;

<%
dh = DateDiff("h", Now(), (Now()-4))

Response.Write dh
%>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.