Solved

ASP - Date Diff

Posted on 1999-01-18
4
190 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

792 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