Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:03:56+00:00 2026-06-08T19:03:56+00:00

I am running a SQL Statement against imported data from Excel Files. In this

  • 0

I am running a SQL Statement against imported data from Excel Files.
In this SQL I am checking if the users have entered dates properly by using IsDate function. Since this is a raw data that hasn’t been converted yet, all dates are stored in a varchar data type field.

In some circumstances IsDate returns 1 (valid date) when there is clearly an incorrect date format entered by the user.

For Example:

07/001/2012

2012-07-002

007/002/2012

Any Suggestions on how to handle this problem?

SELECT *
  FROM tblImport
 WHERE (ISDATE(dt) = 0 
        AND (dt is not null AND dt <> ''))

Thanks!

p.s. Smacking users’ did not help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:03:57+00:00Added an answer on June 8, 2026 at 7:03 pm

    I do a lot of data conversion work and here is a function that I created and use it practically everyday to weed out the bad dates:

    CREATE FUNCTION dbo.fnCheckDate
    (@InDate nvarchar(50))
    RETURNS DATETIME
    AS
        BEGIN
            declare @Return DATETIME
    
            select @return = CASE WHEN ISDATE(@InDate) = 1
                                THEN CASE WHEN CAST(@InDate as DATETIME) BETWEEN '1/1/1901 12:00:00 AM' AND '6/6/2079 12:00:00 AM'
                                        THEN @InDate
                                        ELSE null
                                        END
                                ELSE null
                                END
            return @return
        END
    GO
    

    Results:

    SELECT dbo.fnCheckDate('07/001/2012') --> Returns 2012-07-01 00:00:00.000
    SELECT dbo.fnCheckDate('2012-07-002') --> Returns 2012-07-01 00:00:00.000
    SELECT dbo.fnCheckDate('007/002/2012') --> Returns 2012-07-01 00:00:00.000
    SELECT dbo.fnCheckDate('00/002/2012') --> Returns Null
    SELECT dbo.fnCheckDate('006/031/2012') --> Returns Null
    SELECT dbo.fnCheckDate('') --> Returns Null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL update statement I am running from inside a PHP program.
I have the following in my SQL where clause. This is running against an
I have problems running this sql statement. It works fine if I run it
I have a SQL statement in C# (.NET Framework 4 running against SQL Server
Possible Duplicate: running sql statement from excel vba Here's the excerpt that's causing the
I have a T-SQL statement that I am running against a table with many
I'm running SQL Server 2000 and I need to export the SQL Statement from
I am running an SQL statement: $sql = SELECT pic, userid FROM user_details INNER
We're running SQL 6.5 though ADO and we have the oddest problem. This sentence
I have an weird issue, I am running the following SQL statement: SELECT *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.