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

  • Home
  • SEARCH
  • 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 5952479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:41:16+00:00 2026-05-22T17:41:16+00:00

I need to validate a column having time ranges like ‘8:00 am – 9:00

  • 0

I need to validate a column having time ranges like ‘8:00 am – 9:00 pm’ I need to split this column into two and update to my table with the date with current date but the time from the range for example “2011-05-23 08:00:00” And “2011-05-23 21:00:00” for the range record. kindly help. Also I need to process if the data is ‘8:00 a.m. – 9:00 p.m.’, ‘8:00 a.m – 9:00 p.m’ or ‘8:00 am – 12:00 noon’. If there is no “-” need to reject the data for the record.

  • 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-22T17:41:16+00:00Added an answer on May 22, 2026 at 5:41 pm

    Here’s a basic solution, which, I think, could well be used as a starting point:

    DECLARE @Today datetime = CAST(GETDATE() AS date);
    
    WITH datasource (TimeRange) AS (
      SELECT '10 a.m. - 1 p.m.' UNION ALL
      SELECT '8 am - 12 noon' UNION ALL
      SELECT '12 noon - 4 p.m.' UNION ALL
      SELECT '9 - 10 am' UNION ALL
      SELECT '10 am 1 pm'
    ),
    HyphensIncluded AS (
      SELECT *, HyphenPos = CHARINDEX('-', TimeRange)
      FROM datasource
      WHERE CHARINDEX('-', TimeRange) > 0
    ),
    Split AS (
      SELECT
        *,
        StartTimeStr = REPLACE(
          REPLACE(
            LTRIM(RTRIM(SUBSTRING(TimeRange, 0, HyphenPos))),
            '.',
            ''
          ),
          'noon',
          'pm'
        ),
        EndTimeStr = REPLACE(
          REPLACE(
            LTRIM(SUBSTRING(TimeRange, HyphenPos + 1, LEN(TimeRange) - HyphenPos)),
            '.',
            ''
          ),
          'noon',
          'pm'
        )
      FROM HyphensIncluded
    ),
    Validated AS (
      SELECT *
      FROM Split
      WHERE ISDATE(StartTimeStr) = 1
        AND ISDATE(EndTimeStr) = 1
    )
    SELECT
      StartTimestamp = @Today + StartTimeStr,
      EndTimestamp   = @Today + EndTimeStr
    FROM Validated
    

    Output:

    StartTimestamp          EndTimestamp
    ----------------------- -----------------------
    2011-05-23 10:00:00.000 2011-05-23 13:00:00.000
    2011-05-23 08:00:00.000 2011-05-23 12:00:00.000
    2011-05-23 12:00:00.000 2011-05-23 16:00:00.000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to validate a date/time field on a webpage but want it to
I need to validate this simple pick list: <select name=<%= key %>> <option value=ETC
I don't need to validate that the IP address is reachable or anything like
I have an input db2 table with two elements: loan_number, debt_to_income; this table's name
I need to check If a column value (string) in SQL server table starts
I need to validate two fields only if a third field has a specific
I have this page which has several TextAreas (asp.net mvc). I need to validate
I need to validate an XML string (and not a file) against a DTD
I need to validate the email address of my users. Unfortunately, making a validator
I need to validate a certain property to one of my classes. When I

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.