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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:40:04+00:00 2026-06-06T20:40:04+00:00

I have a database with a ValidDate field – it’s a string(we made a

  • 0

I have a database with a ValidDate field – it’s a string(we made a mistake, it should be a datetime, but we can’t modify the database now.)

and now I want to compare this filed with a parameter(validDateStart) from the website:

priceList = priceList.Where(p => Convert.ToDateTime(p.ValidDate) >= Convert.ToDateTime(validDateStart));
var list = initPriceList.ToList();

But I get an error: The method ToDateTime is not implemented.

Can anybody give me some help? Thanks!

  • 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-06T20:40:05+00:00Added an answer on June 6, 2026 at 8:40 pm

    This is not supported in Linq to Entities (nor Linq to SQL to my knowledge). Remember that your query is executed on the database – where there is simply no equivalent for Convert.ToDateTime.

    Any string parsing in your query would really just be a workaround – as a real solution make those columns not strings but datetime in the database and you would not have this problem in the first place.

    A hacky workaround would be materializing all rows (you can use AsEnumerable() for that), then doing the parsing – this will have bad performance though but might work good enough if there are few rows:

    var startDate = DateTime.Parse(validDateStart);
    var list = priceList.AsEnumerable()
                        .Where(p => DateTime.Parse(p.ValidDate) >= startDate);
                        .ToList();
    

    Edit:

    With your example update it looks like you can just do string comparisons to do what you wanted – granted it’s still a hack but would perform much better than materializing all rows. This is possible because your date format puts the most significant numbers first, then the less significant parts – it’s year, then month, then day (should this not be the case and the day comes before the month in your example this solution will not work).

    Assuming your input string validDateStart is in the same format as well you can just do:

    var list = priceList.Where(p => p.ValidDate.CompareTo(validDateStart) >=0);
                        .ToList();
    

    string comparison with String.CompareTo seems to be support both in Linq to Sql as well as Linq to Entities.

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

Sidebar

Related Questions

I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
We have a current database of users who can have any symbol in their
How can I asynchronously validate against a database for a value in form field?
I have a SmallDateTime field in my Sql Server 2008 database to store users
I have a need to validate a field against our database to verify unique-ness.
I have inherited a MySQL database which (for historical reasons) contains a field which
I have database application, I want to allow the user to restore the deleted
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have database, and in one the tables I need change the values of
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1

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.