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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:16:45+00:00 2026-06-15T20:16:45+00:00

I have a query with hard coded dates, in this format startdate >= ‘2012-11-03’

  • 0

I have a query with hard coded dates, in this format

startdate >= '2012-11-03' AND enddate <= '2012-11-30 23:59'

My database date format is ‘mdy’, however I’m sure it will accept yyyy-mm-dd as its the universal date structure.

When I try run this query in SSMS on my target DB connected with a specific database user (userX) I get an error about the date formats

Msg 242, Level 16, State 3, Line 1
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

However, when I run the exact query connected as the SA user, the query executes..

Why is this? I have given userX full dbo permissions (sysadmin etc) and still get the error?

  • 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-15T20:16:46+00:00Added an answer on June 15, 2026 at 8:16 pm

    If you need to specify datetimes using strings, you should use a safe, language-independent format.

    In SQL Server, that’s the ISO-8601 format (slightly adapted), and it supports basically two safe formats for DATETIME that always work – regardless of your language, regional and dateformat settings:

    YYYYMMDD              (e.g. 20121231  for 31st of December 2012)  if you need date only
    
    YYYY-MM-DDTHH:mm:ss   (e.g. 2012-12-31T21:05:00 for 31st of December 2012, 9:05pm)
    

    Note:

    • the first date-only format has no dashes or delimiters!

    • the second format has dashes for the date (can be omitted, too), and there’s a fixed T as delimiter between the date and the time portion of the string

    Update: as per your last comment (on the different default languages for the two users) – try this:

    -- this is how your `SA` interprets the string as datetime....
    SET LANGUAGE english
    SELECT CAST('2012-11-30 23:59' AS DATETIME)   
    

    Works just fine…

    -- this is how your British user interprets teh string as datetime
    SET LANGUAGE british
    SELECT CAST('2012-11-30 23:59' AS DATETIME)
    

    Msg 242, Level 16, State 3, Line 7
    The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

    This tries to interpret the string as 11th of the 30th month of 2012 and obviously, that fails….

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

Sidebar

Related Questions

I have the query below where the date is hard-coded. My objective is to
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
I have query to show the table like this: but I want to PIVOT
I have query with two MtM relations: $em = $this->getEntityManager(); $qb = $em->createQueryBuilder(); $qb
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like this: select empno,name from emp where job = 'CLERK'
I have a query: SELECT * from arrc_Voucher WHERE VoucherNbr REGEXP ^1002 This works
I have a select SQL query which use parallelism, something like this INSERT/*+ APPEND
I have populated a sorted list of dates(stored as strings in the format dd/mm/yyyy)
I'm having a hard time wrapping my head around this Django query. I could

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.