Click here to Skip to main content
13,002,163 members (81,209 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 1 Nov 2007

VBScript IsTime Function

Rate this:
Please Sign up or sign in to vote.
Sample code for IsTime function similar to VBScript's IsDate


It may exist, but my limited internet searching talent could not lead me to a VBScript IsTime function similar to the IsDate function provided by VBScript. So, using old technology, a book, I came up with the following example.

Please see Scott Barbour's comment below. As it turns out, IsDate will do this for you.


The book I mentioned above is VBScript Programmer's Reference, 2nd edition. It's an excellent resource and worth the money for anyone who plans to write even a little VBScript.

Using the code

The code seems to work fairly well. However, I have not performed an exaustive unit test so use at your own peril.

The code accepts a time string str and first checks for an empty string. That check probably isn't necessary, but it was there from some previous attempts so I left it. Second, it uses TimeValue to check for a valid time. TimeValue will create a runtime error if the time string is invalid so I turn off the error control switch with On Error Resume Next. I turn the error control switch back on with On Error GoTo 0 when I'm done.

function IsTime (str)
  if str = "" then
    IsTime = false
    On Error Resume Next
    if Err.number = 0 then
      IsTime = true
      IsTime = false
    end if
    On Error GoTo 0
  end if
end function

Points of Interest

You would think an experienced C++ programmer wouldn't have any trouble with VBScript, but not this guy. Oh well, diversity makes a nerds life interesting. Happy programming!


Submitted, 11/01/2007.
Edited, 11/05/2007


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

GeneralIsDate() will do this Pin
Scott Barbour1-Nov-07 6:14
memberScott Barbour1-Nov-07 6:14 
GeneralRe: IsDate() will do this Pin
sdkjfhsadlkufjhlawuhfp1-Nov-07 7:08
membersdkjfhsadlkufjhlawuhfp1-Nov-07 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170624.1 | Last Updated 1 Nov 2007
Article Copyright 2007 by sdkjfhsadlkufjhlawuhfp
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid