Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Using time conditions in vbs?

Reply
 
Old 12-15-2008   #1 (permalink)
D.P. Roberts


 
 

Using time conditions in vbs?

Hello,
Vista doesn't handle durations properly in the task scheduler, so I'm
interested in building a time condition right into my vbscript file.
Basically, here's what I need:

If time of day is between 8:00AM and 5:00PM Then
continue processing script
Else
end script
End If

Does anyone know how to write this in vbs?

Thanks!


My System SpecsSystem Spec
Old 12-16-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Using time conditions in vbs?


"D.P. Roberts" <dproberts@xxxxxx> wrote in message
news:OgyxQIxXJHA.2444@xxxxxx
Quote:

> Hello,
> Vista doesn't handle durations properly in the task scheduler, so I'm
> interested in building a time condition right into my vbscript file.
> Basically, here's what I need:
>
> If time of day is between 8:00AM and 5:00PM Then
> continue processing script
> Else
> end script
> End If
>
> Does anyone know how to write this in vbs?
>
> Thanks!
This should get you started:
If Hour(Now()) >= 8 And Hour(Now()) < 17


My System SpecsSystem Spec
Old 12-16-2008   #3 (permalink)
D.P. Roberts


 
 

Re: Using time conditions in vbs?

That is exactly what I needed - thank you!

"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:urLSZ$0XJHA.5312@xxxxxx
Quote:

>
> "D.P. Roberts" <dproberts@xxxxxx> wrote in message
> news:OgyxQIxXJHA.2444@xxxxxx
Quote:

>> Hello,
>> Vista doesn't handle durations properly in the task scheduler, so I'm
>> interested in building a time condition right into my vbscript file.
>> Basically, here's what I need:
>>
>> If time of day is between 8:00AM and 5:00PM Then
>> continue processing script
>> Else
>> end script
>> End If
>>
>> Does anyone know how to write this in vbs?
>>
>> Thanks!
>
> This should get you started:
> If Hour(Now()) >= 8 And Hour(Now()) < 17
>
>
My System SpecsSystem Spec
Old 12-17-2008   #4 (permalink)
Chip Orange


 
 

Re: Using time conditions in vbs?


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:urLSZ$0XJHA.5312@xxxxxx
Quote:

>
> "D.P. Roberts" <dproberts@xxxxxx> wrote in message
> news:OgyxQIxXJHA.2444@xxxxxx
Quote:

>> Hello,
>> Vista doesn't handle durations properly in the task scheduler, so I'm
>> interested in building a time condition right into my vbscript file.
>> Basically, here's what I need:
>>
>> If time of day is between 8:00AM and 5:00PM Then
>> continue processing script
>> Else
>> end script
>> End If
>>
>> Does anyone know how to write this in vbs?
>>
>> Thanks!
>
> This should get you started:
> If Hour(Now()) >= 8 And Hour(Now()) < 17
>
>
I too need to understand time and it's possibilities in VBScript. Is it
possible to do date/time arithmetic in VBScript? I need to take the
difference between 2 times and come up with the number of seconds that have
passed, is this possible?

thanks.

Chip




My System SpecsSystem Spec
Old 12-17-2008   #5 (permalink)
Evertjan.


 
 

Re: Using time conditions in vbs?

Chip Orange wrote on 18 dec 2008 in microsoft.public.scripting.vbscript:
Quote:

> I too need to understand time and it's possibilities in VBScript. Is
> it possible to do date/time arithmetic in VBScript? I need to take
> the difference between 2 times and come up with the number of seconds
> that have passed, is this possible?
DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])


Arguments
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



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
My System SpecsSystem Spec
Old 12-17-2008   #6 (permalink)
Pegasus \(MVP\)


 
 

Re: Using time conditions in vbs?


"Chip Orange" <Chip.Orange@xxxxxx> wrote in message
news:O1dl6sJYJHA.2620@xxxxxx
Quote:

>
> "Pegasus (MVP)" <I.can@xxxxxx> wrote in message
> news:urLSZ$0XJHA.5312@xxxxxx
Quote:

>>
>> "D.P. Roberts" <dproberts@xxxxxx> wrote in message
>> news:OgyxQIxXJHA.2444@xxxxxx
Quote:

>>> Hello,
>>> Vista doesn't handle durations properly in the task scheduler, so I'm
>>> interested in building a time condition right into my vbscript file.
>>> Basically, here's what I need:
>>>
>>> If time of day is between 8:00AM and 5:00PM Then
>>> continue processing script
>>> Else
>>> end script
>>> End If
>>>
>>> Does anyone know how to write this in vbs?
>>>
>>> Thanks!
>>
>> This should get you started:
>> If Hour(Now()) >= 8 And Hour(Now()) < 17
>>
>>
>
> I too need to understand time and it's possibilities in VBScript. Is it
> possible to do date/time arithmetic in VBScript? I need to take the
> difference between 2 times and come up with the number of seconds that
> have passed, is this possible?
>
> thanks.
>
> Chip
I recommend that you download the file script56.chm from the Microsoft site.
It explains all of these basic VB Script functions.


My System SpecsSystem Spec
Old 12-17-2008   #7 (permalink)
Richard Mueller [MVP]


 
 

Re: Using time conditions in vbs?

There is also a similar DateAdd function. Check the VBScript help files. To
assign a date literal, enclose in "#" characters. For example:

dtmStart = #Dec 18, 2008 10:00 AM#
dtmEnd = DateAdd("d", dtmStart, 20)
Wscript.Echo dtmStart
Wscript.Echo dtmEnd
lngSeconds = DateDiff("s", dtmStart, dtmEnd)
Wscript.Echo CStr(lngSeconds)

dtmStart = #Dec 18, 2008 10:00 AM#
dtmEnd = #Jan 3, 2009 02:00 PM#
lngSeconds = DateDiff("s", dtmStart, dtmEnd)
Wscript.Echo CStr(lngSeconds)

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Evertjan." <exjxw.hannivoort@xxxxxx> wrote in message
news:Xns9B7816EA3009eejj99@xxxxxx
Quote:

> Chip Orange wrote on 18 dec 2008 in microsoft.public.scripting.vbscript:
>
Quote:

>> I too need to understand time and it's possibilities in VBScript. Is
>> it possible to do date/time arithmetic in VBScript? I need to take
>> the difference between 2 times and come up with the number of seconds
>> that have passed, is this possible?
>
> DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
>
>
> Arguments
> 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
>
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

My System SpecsSystem Spec
Old 12-18-2008   #8 (permalink)
Chip Orange


 
 

Re: Using time conditions in vbs?


"Pegasus (MVP)" <I.can@xxxxxx> wrote in message
news:%23AcD11JYJHA.4772@xxxxxx
Quote:

>
> "Chip Orange" <Chip.Orange@xxxxxx> wrote in message
> news:O1dl6sJYJHA.2620@xxxxxx
Quote:

>>
>> "Pegasus (MVP)" <I.can@xxxxxx> wrote in message
>> news:urLSZ$0XJHA.5312@xxxxxx
Quote:

>>>
>>> "D.P. Roberts" <dproberts@xxxxxx> wrote in message
>>> news:OgyxQIxXJHA.2444@xxxxxx
>>>> Hello,
>>>> Vista doesn't handle durations properly in the task scheduler, so I'm
>>>> interested in building a time condition right into my vbscript file.
>>>> Basically, here's what I need:
>>>>
>>>> If time of day is between 8:00AM and 5:00PM Then
>>>> continue processing script
>>>> Else
>>>> end script
>>>> End If
>>>>
>>>> Does anyone know how to write this in vbs?
>>>>
>>>> Thanks!
>>>
>>> This should get you started:
>>> If Hour(Now()) >= 8 And Hour(Now()) < 17
>>>
>>>
>>
>> I too need to understand time and it's possibilities in VBScript. Is it
>> possible to do date/time arithmetic in VBScript? I need to take the
>> difference between 2 times and come up with the number of seconds that
>> have passed, is this possible?
>>
>> thanks.
>>
>> Chip
>
> I recommend that you download the file script56.chm from the Microsoft
> site. It explains all of these basic VB Script functions.
>
Thank you to everyone who answered.

I do have script56, but it wasn't clear to me (I don't remember where I was
reading), if DateDiff would return only days or would do time arithmetic and
return seconds.

I'm coming from visual foxpro, which has a date and a date/time variable
type, and can do arithmetic in either set of units returning the result
based on the types used in the expression.

thanks again,



Chip

Thanks again,

Chip



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Multiple IF Conditions VB Script
Changing the time zone changes the appointment time in calendar .NET General
Internet Time Synchronization Incorrect - Showing Standard Time PowerShell
Accept terms & conditions message for Excel worksheets Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46