Solved

ASP - Date Diff

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

948 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now