Time validation (IsTime)

Posted on 2005-05-04
Last Modified: 2008-02-01
Hi, All!
The problem is I'm trying to move my data from Excel spreadsheet to  MS SQL DB.
It's very important to keep data clean, so I need validate some columns, one of them time
Let say time is 10:59a
IsDate("10:59a") = true
But it's wrong, SQL Server won't accept it.
Any ideas how to validate time like that.
Question by:bogdem
    LVL 18

    Accepted Solution

    You could wirte an 'IsSQLServerDate' function and use tha instead.
    Here's one it will need some work but you can get the idea of how to write one.

    Public Function IsSQLServerDate(ByVal vIn)

        IsSQLServerDate = False
        If IsDate(vIn) Then
            IsSQLServerDate = True
            If Right(vIn, 1) = "a" Then
                IsSQLServerDate = False
            End If
        End If

    End Function

    LVL 6

    Expert Comment

    maybe because the native datatype for SQL is datetime or smalldatetime. which means that you need to pass the Date portion instead of just the time. so instead of placing "10:59a", it should be something like "05/04/2005 10:59am".

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now