Re: hot to round time to next day, next week or next month?
- From: Apricot <yilu@xxxxxxxx>
- Date: Fri, 17 Mar 2006 23:54:47 +0800
Thank everybody!
Maybe I didn't put myself clear, and the example is just too simple,
can't stand for a typical scenario.
The problem is, I'm doing a test. The AUT (application under test) has
scheduled tasks, which admin can set it run at every month, evey day
or every week. When he customize a weekly task, AUT will use next
sunday (0:00:00 24h by default) as the first time to run the task. In
our test, I can't wait to that long, so I have to adjust machine's
time. But the first thing is, I need to know what the time it is.
Now I use the below functions to do this:
Function RoundToMonth (varDateTime)
varDateTime = DateAdd("m", 1, varDateTime)
RoundToMonth = Year(varDateTime) & "/" & Month(varDateTime) & "/01"
End Function
Function RoundToWeek (varDateTime)
const worldStart = "1970-1-4 0:00:00"
secs = DateDiff("s", worldStart, varDateTime)
secs = (secs \ ( 7 * 24 * 3600) + 1) * (7 * 24 * 3600)
RoundToWeek = DateAdd("s", secs, worldStart)
End Function
Function RoundToDay (varDateTime)
'wscript.echo "before add " & varDateTime
varDateTime = DateAdd("d", 1, varDateTime)
'wscript.echo "after add " & varDateTime
RoundToDay = Year(varDateTime) & "/" & Month(varDateTime) & "/" &
Day(varDateTime)
'wscript.echo "After round " & varDateTime
End Function
Function RoundToHour (varDateTime)
Dim worldStart : worldStart = "1970/01/01 0:00:00"
hrs = DateDiff("h", worldStart, varDateTime)
RoundToHour = DateAdd("h", hrs + 1, worldStart)
End Function
It works fine on my machine.
RoundToMonth( "2006-12-29 0:00:00") yields "2007/1/01 0:00:00"
RoundToWeek( "2006-12-29 0:00:00") yields "2006-12-31"
Just as what I want.
Sorry for response late. It tooks me a while to find my post.
Hi Guys:
I have a scheduled task, should be run at every day, or every
first day of next week, or every first day of next month (from now).
I'm wondering if it's possible that:
Given today = March 13, 2006
Then URoundWeek(today) == March 20, 2006
URoundMonth(today) == April 1, 2006
Thanks in advance.
.
- Follow-Ups:
- Re: hot to round time to next day, next week or next month?
- From: Dr John Stockton
- Re: hot to round time to next day, next week or next month?
- References:
- hot to round time to next day, next week or next month?
- From: Apricot
- hot to round time to next day, next week or next month?
- Prev by Date: Error Updating Access DB
- Next by Date: Why GetStringValue return NULL?
- Previous by thread: Re: hot to round time to next day, next week or next month?
- Next by thread: Re: hot to round time to next day, next week or next month?
- Index(es):
Relevant Pages
|