【问题标题】:How long time till a Weekday or a Date距离工作日或日期还有多长时间
【发布时间】:2012-08-02 22:52:08
【问题描述】:

我想知道从Now 到特定的Weekday 需要多长时间。 我到处搜索,但找不到任何东西。

我认为我必须以某种方式将DateDiff-函数与WeekDay-函数一起使用。

场景是:

我有变量 varWeekDay 与星期几,例如:1 / 2 / 3 / 4 / 5 / 6 / 7

还有一个变量 varStartTime 与一天中的时间:hh:mm

最后一个变量varStopTime 也是一天中的时间: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

“多长时间”可以是:“从现在起 2 天 3 小时 27 分钟”

应该从特定的日期时间生成相同的输出。例如:06/08/2012 23:55 是“从现在开始 1 天 13 分钟”

真心希望大家帮忙! :)

【问题讨论】:

    标签: datetime asp-classic time weekday


    【解决方案1】:

    我不完全了解您需要的开始时间和结束时间,但此脚本会告诉您从现在到一周中特定日期的开始之间有多少时间。

    <%
    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 />")
    %>
    

    【讨论】:

    • 抱歉回复晚了...在对我自己的项目进行了一些调整后,它就像一个魅力:) 所以答案很棒!
    猜你喜欢
    • 2012-08-13
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    相关资源
    最近更新 更多