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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:34:31+00:00 2026-06-17T05:34:31+00:00

I have a column that store date and time values in the format YYYY-MM-DD

  • 0

I have a column that store date and time values in the format YYYY-MM-DD HH:MM:SS.MSS. I have another table that store date and time value as string in the format ‘M/D/YYYY HH:MM:SS AM’.

Now how do I convert YYYY-MM-DD HH:MM:SS.MSS this format to M/D/YYYY HH:MM:SS AM. After conversion can I able to compare conversion date to the datetime string.
for e.g

A.Date_time = ‘2013-01-08 12:04:00.000’
B.Date_time = convert ( A.Date_time) — convert in format M/D/YYYY HH:MM:SS AM
…

if(B.Date_time = ‘convert (A.Date_time)’ — how can I can compare conversion date with the datetime string.
…

  • 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-17T05:34:32+00:00Added an answer on June 17, 2026 at 5:34 am

    Don’t convert to string to compare, convert to dates to compare.

    SELECT <cols>
      FROM A
      INNER JOIN B
      ON A.Date_time = CONVERT(DATETIME, B.Date_time, 101);
    

    You may need to clean up data first – when you use a string to store a date (which you should never do for a variety of reasons), anyone can stuff any junk in there without validation. So there is no guarantee that all of your values can be successfully converted to a datetime.

    For the changed requirements we can try sussing the datetime portion of the terrible string in this way:

    SELECT <cols>
      FROM A
      INNER JOIN B
      ON A.Date_time = CONVERT(DATETIME, 
       SUBSTRING(B.Date_time, CHARINDEX(' - ', B.Date_time) + 3, 255), 101);
    

    You can even pull that out first, e.g.

    ;WITH x AS (SELECT B.Date_time, RealDateTime = CONVERT(DATETIME, 
       SUBSTRING(B.Date_time, CHARINDEX(' - ', B.Date_time) + 3, 255), 101)
       FROM B
    )
    SELECT x.Date_time, x.RealDateTime FROM x
    -- add joins, comparisons, etc.
    

    IMHO you should focus on fixing the data types, not working around the differences. Or at least arguing with the people who designed this mess to clean it up.

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

Sidebar

Related Questions

I have legacy DB that store dates that means no-date as 9999-21-31, The column
I have mysql table that has a column that stores xml as a string.
Right now I have this code: $mysqldate = date(time()); mysql_query(INSERT INTO permissions (date) VALUES
I have a date time that I generate like this: DateTime myDateTime = DateTime.Now;
I have a date in the string format in a table and I need
I have a table with 1 column that stores the ID auto_increment and with
I have a column in my table that stores max 2 characters. For eg.
I have a table that has a certain numeric column called Score . I
I have a DATETIME column that stores values such as: 2012-05-20 14:00:00 How do
I have a table with a date and time field. I'm having difficulty understanding

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.