Solved

ASP - Date Diff

Posted on 1999-01-18
4
180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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

11 Experts available now in Live!

Get 1:1 Help Now