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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:45:31+00:00 2026-06-10T04:45:31+00:00

I want to count data of each day from database using the for loop.

  • 0

I want to count data of each day from database using the for loop. Here, I don’t know to get the begining of day (start from 12 am) and end of that day ( 12 pm) from value of only date. In below code startDate and endDate have only date value e.g. 2/11/2012.

for (DateTime dates = startDate; dates <= endDate; dates.AddDays(1))
{
    DateTime BeginingOfDay = begining of value variable dates; // 2/2/2012 00:00:00
    DateTime EndOfDay =  at end of value variable dates; // 2/2/2012 23:59:59
    int count = (from u in db.CDRs where (u.StartTime >= BeginingOfDay && u.StartTime <= EndOfDay) select u).Count();;

    dictionary.Add(dates.ToString("MM/dd/yyyy"), count);
 }
  • 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-10T04:45:33+00:00Added an answer on June 10, 2026 at 4:45 am

    The best way to deal with this is to use the right combination of lessthan/greaterthan operators with midnight on day n, and midnight on day n+1

    so given a day, eg

    var date = new Date(2012,8,24); // today
    

    get midnight on that day (start of the day)

    var start = new Date(date.Year, date.Month, date.Day, 0,0,0); // could also be date.Date
    

    and to get midnight on the next day just add 1 day

    var end = start.AddDays(1);
    

    now use greater-than-or-equal-to for the start, and less-than for the end:

    var inRange = x.StartTime>=start && x.EndTime<end
    

    Put together into your example becomes:

    for (DateTime dates = startDate; dates <= endDate; dates.AddDays(1))
    {
        DateTime BeginingOfDay = new DateTime(dates.Year,dates.Month,dates.Day,0,0,0);
        DateTime EndOfDay =  BeginingOfDay.AddDays(1);
        int count = (from u in db.CDRs where (u.StartTime >= BeginingOfDay && u.StartTime < EndOfDay) select u).Count();;
    
        dictionary.Add(dates.ToString("MM/dd/yyyy"), count);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which returns two rows of data as count. I want
I want to count the number of accounts from the resulting table generated from
I have the following data in a database table, Columns : Date, Hour(from 1
I am retrieving a fetch from my core data database and trying to iterate
I want to get the number of Registrations back from a time period (say
I need to get summary data from many many rows. The summary fields are
I want to generate a table showing how many users were created each day.
I have a dynamic range in an Excel sheet. DATA_TABLE =OFFSET(DATA!$B$3,0,0,COUNTA(DATA!$B:$B)-1,0) I want to
I want to count number of files in a folder in a remote host.
I want to count the numbers of hard tab characters in my documents in

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.