Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


[Solved] Time/Minute problem

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,50903
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> [Solved] Time/Minute problem
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 [Solved] Time/Minute problem - 8/17/2007 5:24:23 AM   
  sheepz


Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
i've searched the forum but couldn't figure out how to subtract and figure out time.  here are the links i found and use for reference:

http://www.pctools.com/guides/scripting/id/23/?act=reference
https://www.microsoft.com/technet/scriptcenter/guide/sas_vbs_ufbq.mspx?mfr=true

heres what i want to test.  i want to check every day if i'm within the time windows of 9:30am thru 9:45am.  so this means i'm not concerned which day it is.  i want to check against current time and see if it's within my 15 min mark.  if it's before 9:30am or past 9:45am then do nothing.  heres what i have but it doesn't work, gives me a weird value, or maybe i'm not reading it correctly

iLimit = 15 'The time limit
strCurrentTime = TimeValue(Now) 'Grab current Time
strSetTime = TimeValue("09:30:00") 'Time to check against
strResult = strCurrentTime - strSetTime 'do the math
MsgBox strResult 'check the result
'check if within time limit
If strResult = iLimit Then
MsgBox "Time within 9:30am through 9:45am"
End If

< Message edited by sheepz -- 8/23/2007 2:09:37 PM >
 
 
Post #: 1
 
 RE: Time/Minute problem - 8/17/2007 5:50:23 AM   
  CondoPC


Posts: 118
Score: 0
Joined: 7/23/2007
Status: offline
I think that if you review this recent post, it maygive you some ideas on how this can be accomplished:
http://www.visualbasicscript.com/m.aspx?m=50876&mpage=1&key=

Also, your second link to use DatePart() shoudl give you an idea on how to get the specific time back and compare it to your required timeframe. I provided an example of the process, although I didn't give the specific values because it is good to learn it on your own, you'll retain it better than if it is given to you.

dteStartTime = <formatted start time>
dteEndTime = <formatted end time>
dteCurrTime = <code to get the time from Now()>
'compare to your span
If dteCurrTime > dteStartTime AND dteCurrTime < dteEndTime Then
   wscript.echo "time meets required window"
Else
   wscript.echo "time outside of window"
End If

< Message edited by CondoPC -- 8/17/2007 6:02:11 AM >

(in reply to sheepz)
 
 
Post #: 2
 
 RE: Time/Minute problem - 8/17/2007 9:40:27 AM   
  sheepz


Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
thanks condo, i kept trying to use Minute(Now) to extract the minutes and Hour(Now)... didn't know how to go about it... but this line is exacty what i was looking for, thanks!

'n is for Minutes
strTimeDiffer =  DateDiff("n", TimeStamp, Now())

(in reply to sheepz)
 
 
Post #: 3
 
 RE: Time/Minute problem - 8/17/2007 11:52:57 AM   
  sheepz


Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
i read DateDiff() in msdn but overlooked it because the name is very misleading.  i thought it only dealt with the date not the time.

(in reply to sheepz)
 
 
Post #: 4
 
 RE: Time/Minute problem - 8/17/2007 4:26:56 PM   
  CondoPC


Posts: 118
Score: 0
Joined: 7/23/2007
Status: offline
sorry if this loops you back some more. I have a function that I picked up somewhere that I use to format Now() into a string that I append to a filename to make it unique. You should be able to get enough information from it to get your time stamp so that you can then compare it to you timeframe.

'==========================================
'Format Date and Time
'==========================================
'This will format the date and time to be used in a filename
Function rDateTime()
 'get 24-hour Hour and Minute and Second
myHour = Left(FormatDateTime(Time, vbShortTime),2)
myMinute = Right(FormatDateTime(Time, vbShortTime),2)
mySecond = DatePart("s" , FormatDateTime(Time, vbLongTime))

 'concatenate the time
myTime = myHour & myMinute & mySecond

'get Month and Day and Year
   myDayName = DatePart("D",Date)
   myMonthName = DatePart("M",Date)
   myYear = DatePart("YYYY",Date)
'concatenate the date
myDay = myYear & myMonthName & myDayName

'return formatted values
rDateTime = myDay & myTime

End Function

(in reply to sheepz)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> [Solved] Time/Minute problem Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts