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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:54:40+00:00 2026-05-13T05:54:40+00:00

I have a table that has multiple records with a start date (PlacementDate) and

  • 0

I have a table that has multiple records with a start date (PlacementDate) and end date (Pulled Date). I’m passing start date and end date parameters into this function which needs to return the records that intersect the start and end date passed in and also specify how many days each record intersects for.

Getting the records that intersect is easy, getting the number of days of intersection between the date ranges is not so easy… Here’s what I have so far:

            var query = from d in db.TelemetryDevices
                    join p in db.DevicePlacements on d.TelemetryDeviceID equals p.TelemetryDeviceID
                    where d.CompanyID == companyId && d.BillingPlanID == billingPlanId
                        && (
                        (p.PlacementDate <= startDate && (p.PulledDate != null ? p.PulledDate.Value : DateTime.MaxValue) >= endDate)// { start - end }
                        || (p.PlacementDate <= startDate && (p.PulledDate != null ? p.PulledDate.Value : DateTime.MaxValue) >= startDate)// { start } end
                        || (p.PlacementDate >= startDate && (p.PulledDate != null ? p.PulledDate.Value : DateTime.MaxValue) <= endDate)// start { } end
                        || (p.PlacementDate >= startDate && (p.PulledDate != null ? p.PulledDate.Value : DateTime.MaxValue) >= endDate)// start { end }
                        )
                    select new DeviceView
                    {
                        TelemetryDeviceID = d.TelemetryDeviceID
                    };

Any ideas as to how to solve this would be greatly appreciated.

  • 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-13T05:54:41+00:00Added an answer on May 13, 2026 at 5:54 am

    Have a look at this.

    If I misunderstood, please let me know.

    List<MyClass> dates = new List<MyClass>();
    dates.Add(new MyClass { StartDate = new DateTime(2009, 01, 01), EndDate = new DateTime(2009, 01, 08) });
    dates.Add(new MyClass { StartDate = new DateTime(2009, 01, 15), EndDate = new DateTime(2009, 01, 20) });
    dates.Add(new MyClass { StartDate = new DateTime(2009, 01, 22), EndDate = new DateTime(2009, 01, 31) });
    DateTime sDate = new DateTime(2009, 01, 07);
    DateTime eDate = new DateTime(2009, 01, 25);
    var result = (from d in dates
                 orderby d.StartDate
                 where !(eDate < d.StartDate || sDate > d.EndDate)
                 select new
                 {
                     Days = (d.EndDate <= eDate && d.StartDate >= sDate ? d.EndDate.Subtract(d.StartDate).Days:
                     sDate >= d.StartDate && sDate <= d.EndDate && eDate >= d.EndDate ? d.EndDate.Subtract(sDate).Days:
                     eDate >= d.StartDate && eDate <= d.EndDate && sDate <= d.StartDate ? eDate.Subtract(d.StartDate).Days:
                     eDate <= d.EndDate && sDate >= d.StartDate ? eDate.Subtract(sDate).Days : 0)
                     }).Sum(x => x.Days);
    int total = result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 265k
  • Answers 265k
  • 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 Its not the same problem. In the original problem, the… May 13, 2026 at 12:24 pm
  • Editorial Team
    Editorial Team added an answer Put a file named log4j.properties in the root of your… May 13, 2026 at 12:24 pm
  • Editorial Team
    Editorial Team added an answer You get it as $row[field_name], And if you have two… May 13, 2026 at 12:24 pm

Related Questions

Rookie question I know. I have a table with about 10 fields, one of
I have a table that has a bunch of fields. The fields can be
I have a table of reports that has these relevant fields: user_id (int 11)
I have a dictionary table called car_status that has an 'id' column and a
I need to store user entered changes to a particular table, but not show

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.