Question

I want to find out how long time there is till a specific Weekday from Now. I have searched everywhere, but can't really find anything.

I THINK I have to use the DateDiff-function together with the WeekDay-function somehow.

The scenario is:

I have variable varWeekDay with the day of the week, ex: 1 / 2 / 3 / 4 / 5 / 6 / 7

And another variable varStartTime with a time of the day: hh:mm

And the last variable varStopTime also with a time of the day: hh:mm

if varWeekday = Weekday(now, 2) and varStartTime < formatdatetime(now, 4) then
  .... Write how long time till start in hours / minutes
elseif varWeekday = Weekday(now, 2) and varStartTime >= formatdatetime(now, 4) and varStopTime < formatdatetime(now, 4) then
  response.write("Already started!")
else
  .... Write how long time till start in days / hours / minutes
end if

"How long time" could be like: "2 days, 3 hours and 27 minutes from now"

The same output should be generated from a specific datetime. Ex: 06/08/2012 23:55 is "1 day and 13 minutes from now"

I really hope you guys can help! :)

Was it helpful?

Solution

I didn't fully understand what you needed with the start time and end time, but this script will tell you how much time there is between now and the start of a specific day of the week.

<%
Dim varNow : varNow = Now()
Dim varWeekday : varWeekday = 7 'This is the weekday to look for (1 is Sunday, 7 is Saturday)

'This next line sets the time to the start of the day
Dim varThisDate : varThisDate = DateSerial(Year(varNow), Month(varNow), Day(varNow))
Dim varThisWeekday
Do
    varThisDate = DateAdd("d", 1, varThisDate)
    varThisWeekday = Weekday(varThisDate)
    If varThisWeekday = varWeekday Then
        Exit Do
    End If
Loop

'These next lines just convert and display the remaining time into the different units
Response.Write("Until next " & WeekdayName(varWeekday) & "<br />")

Dim varSeconds : varSeconds = DateDiff("s", varNow, varThisDate)
Dim varDays : varDays = Int(varSeconds / 60 / 60 / 24)
varSeconds = varSeconds - (varDays * 24 * 60 * 60)
Dim varHours : varHours = Int(varSeconds / 60 / 60)
varSeconds = varSeconds - (varHours * 60 * 60)
Dim varMinutes : varMinutes = Int(varSeconds / 60)
varSeconds = varSeconds - (varMinutes * 60)

Response.Write("Days: " & varDays & "<br />")
Response.Write("Hours: " & varHours & "<br />")
Response.Write("Minutes: " & varMinutes & "<br />")
Response.Write("Seconds: " & varSeconds & "<br />")
%>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top