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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:30:07+00:00 2026-05-15T09:30:07+00:00

I have a C# console application written using Visual Studio 2008. My system culture

  • 0

I have a C# console application written using Visual Studio 2008.

My system culture is en-GB. I have a Linq query that looks like this:

var myDate = "19-May-2010";

var cus = from x in _dataContext.testTable
     where x.CreateDate == Convert.ToDateTime(myDate)
     select x;

The resulting SQL query generates and error because it returns the dates as “19/05/2010” which it interprets as an incorrect date. For some reason even though my system culture is set to en-GB it looks like it’s trying to intrepret it as a en-US date.

Any ideas how I get around this?

Edit: Thanks for the comments about magic strings and var abuse, but that’s not my problem. My problem is that in the conversion from Linq to SQL the dates are being interpreted as US format dates (19/05/2010 is being interpreted as: month nineteen, day 5 and year 2010) resulting in the following error:

System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value

The where clause of the resulting SQL query looks like:

WHERE ([t0].[CreateDate] = '19/05/2010 00:00:00') 

Please note that the exact same Linq query works perfectly in LinqPad.

I’ve tried the following where clause:

where x.CreateDate == DateTime.Today

and still get the error.

Additional Information:

SQL Server Query Visualizer:

SELECT [t0].[field1], [t0].[field2], [t0].[field3] AS [field4], [t0].[field5]
FROM [dbo].[table] AS [t0]
WHERE ([t0].[CreateDateTime] = '19/05/2010 00:00:00') 

Original query:
SELECT [t0].[field1], [t0].[field2], [t0].[field3] AS [field4], [t0].[field5]
FROM [dbo].[table] AS [t0]
WHERE ([t0].[CreateDateTime] = @p0) 
-------------------------------
@p0 [DateTime]: 19/05/2010 00:00:00

LINQPad:

-- Region Parameters
DECLARE @p0 DateTime SET @p0 = '2010-05-19 00:00:00.000'
-- EndRegion
SELECT [t0].[field1], [t0].[field2], [t0].[field3] AS [field4], [t0].[field5]
FROM [table] AS [t0]
WHERE ([t0].[CreateDateTime] = @p0)

In the above I notice that LinqPad presents the date in a different format to VS.

Thanks.

Alan T

  • 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-15T09:30:08+00:00Added an answer on May 15, 2026 at 9:30 am

    Don’t send local strings into the database and ask the database to convert those strings into DateTimes. Just don’t.

    Originally:

    var myDate = "19-May-2010"; 
    
    var cus = from x in _dataContext.testTable 
      where x.CreateDate == Convert.ToDateTime(myDate) 
      select x; 
    
    • Don’t abuse var.
    • Separate actions you intend to occur in the database from actions you intend to occur locally

    So…

    string myInput = "19-May-2010";
    DateTime myDate = Convert.ToDateTime(myInput);
    
    IQueryable<TestTable> cus =
      from x in _dataContext.testTable
      where x.CreateDate == myDate
      select x;
    

    In response to the update.

    • It seems that your app is sending the rightly formatted date times, but it’s using a connection that expects wrongly formatted datetimes.
    • You can change each connection or you can change the login’s defaults: http://support.microsoft.com/kb/173907
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 448k
  • Answers 448k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Create a view with a Collection property and a PostCode… May 15, 2026 at 7:51 pm
  • Editorial Team
    Editorial Team added an answer You need to escape the backslashes in the escape sequences… May 15, 2026 at 7:51 pm
  • Editorial Team
    Editorial Team added an answer From the template_preprocess_node function: $variables['links'] = !empty($node->links) ? theme('links', $node->links,… May 15, 2026 at 7:51 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.