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 3346916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:21:36+00:00 2026-05-18T01:21:36+00:00

This is in MS SQL Server. I have a varchar in the format yyyy-MM-dd-hh.mm.ss.nnnnnn

  • 0

This is in MS SQL Server.

I have a varchar in the format yyyy-MM-dd-hh.mm.ss.nnnnnn

For example: 2010-09-17-20.52.31.870000

I want to convert this into a datetime… but ISDATE function in MSSQL says that is not a valid date and CONVERT won’t work. Is there a way to use the convert function so that I can tell it what format the date is in?

I also want to check first that it is a valid date since the varchar input may contain nothing or it may contain an invalid date.

For example, invalid data of 2010-xx-r7-99.53esdfd.31.870000… I would skip that data and not even try to convert.

  • 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-05-18T01:21:37+00:00Added an answer on May 18, 2026 at 1:21 am

    As far as I’m aware, SQL Server 2005 only supports milliseconds up to 3 digits, so you could replace the periods with colons, and grab the left and right portions (ignoring the hyphen between the day and hours) and come up with something like this:

    DECLARE @myDate varchar(50)
    SET @myDate = '2010-09-17-20.52.31.870000'
    
    PRINT isdate(left(@myDate, 10) + ' ' + 
     replace(substring(@myDate, 12, 12), '.', ':'))  -- Should print '1'
    
    PRINT cast(left(@myDate, 10) + ' ' + 
        replace(substring(@myDate, 12, 12), '.', ':') as datetime)
    

    … which will effectively give you 870 milliseconds

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is on SQL Server 2008. I have several columns I want to convert
This is in SQL Server 2005. I have a varchar column and some rows
This is SQL Server 2008. I have these two tables and a join: DECLARE
In Microsoft SQL Server: I have seen this question several times, but can't see
I have a table like this in SQL Server: varID(PK) dataID(PK) is_used A 1
I have SQL Server 2008 with a table called ProductCategories designed like this: Id
In SQL Server, I have a database abc . In this database I have
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have a SQL Server 2005 output like this: Date | Result | Sum
I currently have this statement in my SQL View (SQL Server 2008 R2) which

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.