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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:15:23+00:00 2026-05-26T03:15:23+00:00

How can I convert the string to datetime using linq to entities …. I

  • 0

How can I convert the string to datetime using linq to entities ….

I have got the below query, where the visit_date column datatype is string…

var memberl = from v in abc.visits
              join m in abc.members on v.member_Id equals m.member_Id
              where Convert.ToDateTime(v.visit_Date) >= startdate && 
                    Convert.ToDateTime(v.visit_Date) <= enddate
              group m by new { m.member_Firstname, 
                               m.member_Lastname, m.member_Id } into g
              orderby g.Count()
              select new
              {
                  numVisits = g.Count(),
                  firstname = g.Key.member_Firstname,
                  lastname = g.Key.member_Lastname
              };

Unfortunately I can’t change the schema …

I have got the error:

linq to entites does not recognise Convert.ToDatetime method

Is there any possible solution for converting string to Datetime?

Updated code:

as per request i Have updated my question

 var data = (from v in abc.visits
                  join m in abc.members on v.member_Id equals m.member_Id
                  select new
                  {
                      MemberID = v.member_Id,
                      VisiteDate = v.visit_Date,
                      FirstName = m.member_Firstname,
                      LastName = m.member_Lastname
                  }).ToList();

      var membersdata = from d in data
                        where Convert.ToDateTime(d.VisiteDate) >= startdate && Convert.ToDateTime(d.VisiteDate) <= enddate
                        group m by new { d.FirstName, d.LastName, d.MemberID } into g
                        orderby g.Count()
                        select new
                        {
                            numVisits = g.Count(),
                            firstname = g.Key.FirstName,
                            lastname = g.Key.LastName
                        }; 
  • 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-26T03:15:23+00:00Added an answer on May 26, 2026 at 3:15 am

    I don’t think EF supports a translation for a String to DateTime or vice-versa conversion.

    As I see it, you have two options, depending on the format of the date in the string field:

    If the format is fairly simple, a string comparison might be enough:

    // Convert the boundaries to strings first
    // TODO: Set the ToString format option to match the database format
    string startDateAsString = startdate.ToString("yyyyMMdd");
    string endDateAsString = enddate.ToString("yyyyMMdd");
    
    // Query based on string comparison
    var memberl = from v in abc.visits
                  join m in abc.members on v.member_Id equals m.member_Id
                  where v.visit_Date.CompareTo(startDateAsString) >= 0 && 
                        v.visit_Date.CompareTo(endDateAsString) <= 0
                  group m by new { m.member_Firstname, 
                                   m.member_Lastname, m.member_Id } into g
                  orderby g.Count()
                  select new
                  {
                      numVisits = g.Count(),
                      firstname = g.Key.member_Firstname,
                      lastname = g.Key.member_Lastname
                  };
    

    If the string representation of the date is more complex, and a simple string comparison cannot help, you might consider creating a view on the visits table, which does the conversion for you at database level:

    CREATE VIEW VisitsWithDate (MemberId, VisitDate)
    AS
    SELECT MemberId, Convert(datetime, VisitDate, 112) -- For instance
    FROM Visits
    

    Followed by importing this view into your DataModel. You might need to do some magic to make the relationships work.

    Hope it helps.

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

Sidebar

Related Questions

How can I convert a string 08:00 to a DateTime datatype? Im trying to
How can I convert this string date to datetime in oracle. 2011-07-28T23:54:14Z Using this
Can we convert a hex string to a byte array using a built-in function
I am converting a string to datetime using DateTime.TryParse in C#. Can somebody tell
I have the following code: DateTime pickerDate = Convert.ToDateTime(pickerWakeupDate.SelectedDate); string enteredStr = pickerDate.ToShortDateString() +
I'm have been trying to convert the foreach statement below to a LINQ statement
I try to convert string type dd.MM.yyyy HH:mm:ss.mmm to the datetime using the way
How can I convert a string to a date time object in javascript by
How can I convert a date time string of the form Feb 25 2010,
Can I convert a string representing a boolean value (e.g., 'true', 'false') into an

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.