Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

diff between time and date?

Posted on 2001-07-17
15
Medium Priority
?
293 Views
Last Modified: 2008-03-17
Can i find the difference between two time variables generated by now(). What is the easiest way to do that?
0
Comment
Question by:rav_chow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +2
15 Comments
 
LVL 1

Expert Comment

by:erezsh
ID: 6290633
Use DateDiff() function:

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

  Erez Sh.
0
 
LVL 1

Expert Comment

by:erezsh
ID: 6290649
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
 
LVL 5

Expert Comment

by:dredge
ID: 6290654
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rav_chow
ID: 6290694
friends, I asked for time.. ie. hour ,min ..
0
 

Expert Comment

by:HabBoy
ID: 6290772
You asked for date and time and erezsh kindly gave you both.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6290797
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 Comment

by:rav_chow
ID: 6290882
Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'DateDiff'

this is the error is get when i try datediff
0
 
LVL 1

Accepted Solution

by:
erezsh earned 300 total points
ID: 6290883
To get the differeces between two dates (and times) in minutes, for example, use:
MinDiff = DateDiff("n", date1, date2)

Please read all of my answer fully.

btw 10x for the support ;)
  Erez Sh.

 
0
 
LVL 18

Expert Comment

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

Author Comment

by:rav_chow
ID: 6290897
Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'DateDiff'

this is the error is get when i try datediff
0
 
LVL 1

Expert Comment

by:erezsh
ID: 6290921
Give me the entire code that you are using so I can tell you what's wrong.
0
 
LVL 1

Expert Comment

by:erezsh
ID: 6290941
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
 
LVL 18

Expert Comment

by:mgfranz
ID: 6290942
You do have IIS installed don't you?
0
 
LVL 1

Expert Comment

by:erezsh
ID: 6290951
(in days)
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6290966
This tells you exactly in hours, the difference betweeen Now annd 4 days ago;

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

Response.Write dh
%>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question