Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

ASP - Date Diff

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
jkb2
Asked:
jkb2
  • 2
  • 2
1 Solution
 
MasseyMCommented:
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
 
jkb2Author Commented:
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
 
MasseyMCommented:
Yes.  YOU just have to use datadiff correctly.

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

0
 
jkb2Author Commented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now