Solved

ASP - Date Diff

Posted on 1999-01-18
4
191 Views
Last Modified: 2013-12-25
I need to calculate the number of months/days/hours/minutes left till a given date in history. Is there anything that will make this easier or will I have to do this manually...
0
Comment
Question by:jkb2
[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
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:MasseyM
ID: 1832326
You can use DateDiff in ASP:

Days from today: <%=DateDiff("d", Now, theDate)%>

DateDiff(interval, date1, date2 [,firstdayofweek[,firstweekofyear]])


The DateDiff function syntax has these parts:

Part Description
interval Required. String expression that is the interval you want to use to calculate the differences between date1 and date2. See Settings section for values.
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.



Settings
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 1

Author Comment

by:jkb2
ID: 1832327
While I can see how the DateDiff will give me number of days, I am in need of not only days but hours/minutes/seconds from Now().

Can DateDiff do this?
0
 
LVL 10

Accepted Solution

by:
MasseyM earned 100 total points
ID: 1832328
Yes.  YOU just have to use datadiff correctly.

Seconds = Datediff("s", olddate, now())
Minutes = Datediff("m", olddate, now())
HOurs = datediff("h", olddate, now())

0
 
LVL 1

Author Comment

by:jkb2
ID: 1832329
For the Most Part you were correct. I was able to use the DateDiff with the "s" flag to get total number of seconds and get back to the number I was looking for...



0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

696 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