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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:08:05+00:00 2026-06-13T13:08:05+00:00

I’m trying to get the date range from last week and 2 weeks ago

  • 0

I’m trying to get the date range from last week and 2 weeks ago from Sunday to Saturday
so today is 10/24/2012, date range is : 10/21/2012 – 10/27/2012

I’m trying to get last week’s date range which is: 10/14/2012 – 10/20/2012
Also the 2 weeks ago’s date range which is: 10/07/2012 – 10/13/2012

I have the right SQL query which is

DECLARE @TodayDayOfWeek INT
DECLARE @EndOfPrevWeek DateTime
DECLARE @StartOfPrevWeek DateTime
DECLARE @EndOf2WeeksAgo DateTime
DECLARE @Start2WeeksAgo DateTime


SET @TodayDayOfWeek = datepart(dw, GetDate())
--get the last day of the previous week (last Sunday)
SET @EndOfPrevWeek = DATEADD(dd, -@TodayDayOfWeek, GetDate())
--get the first day of the previous week (the Monday before last)
SET @StartOfPrevWeek = DATEADD(dd, -(@TodayDayOfWeek+6), GetDate())
SET @EndOf2WeeksAgo = DATEADD(dd, -(@TodayDayOfWeek+7), GetDate())
SET @Start2WeeksAgo = DATEADD(dd, -(@TodayDayOfWeek+13), GetDate())

Select  @StartOfPrevWeek as [Last week start date], @EndOfPrevWeek as [Last Week start date],
@Start2WeeksAgo as [2 Weeks Ago Start], @EndOf2WeeksAgo as [2 Weeks Ago End]    

This results in

[Last week start date] [Last week start date]  [2 Weeks Ago Start] [2 Weeks Ago End] 
10/14/2012             10/20/2012              10/07/2012          10/13/2012

how to i convert this to Linq? I have a date column and need to display dates between these 2 date ranges like

last week date   2 weeks ago
10/15/2012        10/08/2012
10/18/2012        10/11/2012
  • 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-13T13:08:06+00:00Added an answer on June 13, 2026 at 1:08 pm

    The following is a simple Console App that I wrote that shows you one way of accomplishing the task. Just adapt it to your needs…

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace ConsoleApplication5
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<Test> testData = new List<Test>() {
                    new Test() { Id = 1, Date = DateTime.Now.AddDays(-9) },
                    new Test() { Id = 2, Date = DateTime.Now.AddDays(-8) },
                    new Test() { Id = 3, Date = DateTime.Now.AddDays(-16) },
                    new Test() { Id = 4, Date = DateTime.Now.AddDays(-14) },
                    new Test() { Id = 5, Date = DateTime.Now.AddDays(-15) },
                    new Test() { Id = 6, Date = DateTime.Now.AddDays(-10) },
                    new Test() { Id = 7, Date = DateTime.Now.AddDays(-7) }
                };
    
                  DateTime date = DateTime.Now; // 10/24/2012
    
                  DateTime startOneWeekAgo =
                      // prev Sunday 10/14/2012 00:00
                      date.AddDays(-7).Date.AddDays(-(int)date.DayOfWeek),
    
                      // next Sunday 10/21/2012 00:00
                      endOneWeekAgo = startOneWeekAgo.AddDays(7);
    
                  DateTime startTwoWeeksAgo =
                      // prev Sunday 10/07/2012 00:00
                      startOneWeekAgo.AddDays(-7),
    
                      // next Sunday 10/14/2012 00:00
                      endTwoWeeksAgo = endOneWeekAgo.AddDays(-7);
    
                var qryOneWeekAgo =
                                from record in testData
                                where record.Date >= startOneWeekAgo // include start
                                && record.Date < endOneWeekAgo // exclude end
                                select record;
    
                var qryTwoWeeksAgo =
                                 from record in testData
                                 where record.Date >= startTwoWeeksAgo // include start
                                 && record.Date < endTwoWeeksAgo // exclude end
                                 select record;
    
                Console.WriteLine("------- Dates from 1 Week Ago -------");
                foreach (var record in qryOneWeekAgo)
                {
                    Console.WriteLine(
                        string.Format("{0} => {1}", record.Id, record.Date));
                }
    
                Console.WriteLine();
    
                Console.WriteLine("------- Dates from 2 Weeks Ago -------");
                foreach (var record in qryTwoWeeksAgo)
                {
                    Console.WriteLine(
                        string.Format("{0} => {1}", record.Id, record.Date));
                }
    
                Console.ReadKey();
    
            }         
        }
    
        public class Test
        {
            public int Id { get; set; }
            public DateTime Date { get; set; }
        }
    
    }
    

    Output

    ------- Dates from 1 Week Ago -------
    1 => 10/15/2012 12:52:38 PM
    2 => 10/16/2012 12:52:38 PM
    6 => 10/14/2012 12:52:38 PM
    7 => 10/17/2012 12:52:38 PM
    
    ------- Dates from 2 Weeks Ago -------
    3 => 10/8/2012 12:52:38 PM
    4 => 10/10/2012 12:52:38 PM
    5 => 10/9/2012 12:52:38 PM
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.