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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:25:26+00:00 2026-05-28T21:25:26+00:00

I have a date in the string format in a table and I need

  • 0

I have a date in the string format in a table and I need to compare it with the parameter to retrieve all rows that match with the given date. how can I do this? I can’t use DateTime.Parse and Convert.ToDateTime. both of them are not supported (I get an error). Is this possible at all in Linq OR do I have to write a stored procedure for it due to this limitation?

Note: I can’t change the datatype of the column from varchar to DateTime, because that column contains other values as well, not just dates. it is a generic table and the column may contain different types of values based on the values in other columns. changing this design is outside the scope of this question.

sample code (“x” is the date parameter passed into this method):

    from t1 in Table1
    where EntityFunctions.DiffDays(DateTime.Parse(t1.Value),x) == 0
    select new {t1.Col1, t1.Col2};

Update: if I use DateTime.Parse, I get the error “LINQ to Entities does not recognize the method ‘System.DateTime Parse(System.String)’ method, and this method cannot be translated into a store expression.” similar error for Convert.ToDateTime as well.

  • 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-28T21:25:26+00:00Added an answer on May 28, 2026 at 9:25 pm

    (Replicating my comment to paste some sample code)

    If the date is in string format, couldn’t you apply a ToString on your DateTime (presumably x) and then do a string comparison?

    Since you are working on string representations, you need to take care of several issues that would otherwise be handled transparently by DateTime, including:

    • Date-time format discrepancies (dd/MM/yyyy vs MM/dd/yyyy).
    • Presence or absence of leading zeros for single-digit days and months (e.g. 01/01/2011 vs 1/1/2001).
    • Two-digit or four-digit representation of years (e.g. 01/01/2011 vs 01/01/11).
    • Timezone offsets. For example, the date for 2011-01-01 23:30 -01:00 would actually be 2011-01-02.

    The sample code below will work if all your dates are in US format, with two-digit days and months, four-digit years, and no timezone offsets.

    from t1 in Table1
    where t1.Value.StartsWith(x.ToString(@"MM\/dd\/yyyy"))
    select new {t1.Col1, t1.Col2};
    

    Edit: Alternate solution:

    If you can define a view in your database, you can circumvent the problem by casting your VARCHAR to DATETIME selectively. I’m assuming that Value is the name of your date column.

    SELECT CONVERT(DATE, Value, 101) AS Value, Col1, Col2
    FROM Table1
    WHERE ISDATE(Value) = 1
    

    Then, in your LINQ, do a simple DateTime equality check:

    from t1 in Table1
    where t1.Value == x.Date
    select new {t1.Col1, t1.Col2};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field in an Azure table that holds date times in string
I have an error in that m String currentDateTimeString = DateFormat.getDateInstance().format(new Date()); Cursor myCursor=db.query(true,
Hi I have the following date as String format. Input 2010-04-20 05:34:58.0 Output I
I'm a little blockheaded right now… I have a date string in european format
i want to format date to string in hql select, for example i have
I have a string containing a date, and another string containing the date format
I have a date string of the form '2009/05/13 19:19:30 -0400'. It seems that
I have been passed a date string that looks like this: Thu%20Mar%2011%202010%2015%3A09%3A11%20GMT%2B0000%20(BST) I want
I have a varchar column which contains date in following format dd/mm/yyyy I need
I have one column in my table which will store data in string format

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.