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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:02:59+00:00 2026-05-27T22:02:59+00:00

I have two datetime pickers that I’m using to set a start and end

  • 0

I have two datetime pickers that I’m using to set a start and end date for desired records in a database. The “dates” in the database are stored as strings in the format yyyymmdd, but some dates are missing characters (ex. 2001094, which is missing the last digit on the day).

I want to write a single LINQ query that pulls the records for the relevant timespan, but if I just do this:

var = 
    from rec in datacontext 
    where rec.date.substring(0,8) is in the daterange 
    select rec

then I get out of range exceptions for the short stringed records (because they are not 8 characters long).

Right now I’m pulling in the whole table and using two lambdas to (1) remove all the records that don’t begin with 8 integers and then (2) remove all of the now .substring-safe records that don’t match the range. This works, but it’s really ugly.

If I have two conditions in my where clause, does LINQ evaluate them sequentially? So if I say

from ... where (rec.date starts with 8 integers) AND (rec.date is in range) 

will LINQ skip over records when it sees they don’t match the first condition?

The only other thing I can think of (also sort of ugly) is to use .StartsWith instead of .SubString in the initial LINQ queries, and then use lambdas after the initial query to remove the out of range records. This is better than pulling in all rows like I’m doing now, but not really the elegant single query I’m looking for.

if datetimepickers are both in the same year...
var=from ... where rec.date.startswith(yyyy) 'at least I'm not pulling in everything...
var.remove(lambda to remove short date strings)
var.remove(lambda to remove out of range dates)
  • 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-27T22:03:00+00:00Added an answer on May 27, 2026 at 10:03 pm

    In this case, adding a check for the lenght of the string will fix the problem. In this case, LINQ will evaluate the first part of an AND condition and then stop evaluating if it fails. So if it has A && B, if A is false, then it won’t evaluate B

    var=from rec in datacontext where rec.date.length >= 8 && rec.date.substring(0,8) is in the daterange select rec
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two datetime objects; a start date and an end date. I need
I have an entity set that contains two DateTime properties. I want to order
Here's the situation: I have two DateTimePicker controls for the start date and end
If I have a table that (among other columns) has two DATETIME columns, how
I have two applications written in Java that communicate with each other using XML
I have two arraylists that consist of the datetime objects and merging both the
I have two tables: one has a datetime column, the other has a date
I have two Datetime fields that I wish to add together. They are in
I have two date fields that I need to join on. The first is
I have two methods that I'm using as custom tags in a template engine:

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.