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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:06:51+00:00 2026-05-21T00:06:51+00:00

I have the following beast of an SQL (DB2) statement… select ((date(days(date(cast(year(‘2012-03-28’)-6 as char(4))||

  • 0

I have the following beast of an SQL (DB2) statement…

select ((date(days(date(cast(year('2012-03-28')-6 as char(4))|| '-01-01')) -(dayofweek(date(cast(year('2012-03-28')-6 as char(4))|| '-01-01') )-1))+7 days)+(((week('2012-03-28')-2)* 7)+dayofweek('2012-03-28')-1) days) AS CAL_COMP_DATE
from sysibm.sysdummy1

Taking the input date of Wednesday, 2012-03-28, this would return Wednesday, 2006-03-29. Notice that it matched the Thursdays. It matches the corresponding calendar day of previous years.

Is there a more elegant way of accomplishing the same goal in C# or VB.NET? I’ve tried translating this query into VB.NET, but haven’t been able to do so perfectly and it just looks horrible and unmaintainable.

  • 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-21T00:06:52+00:00Added an answer on May 21, 2026 at 12:06 am

    I don’t completely understand the rule for finding that day. But you could use something along these lines:

    var originalDate = new DateTime(2012,03,28);
    var newDate = originalDate.AddYears(-6);
    var daysToAdd = originalDate.DayOfWeek - newDate.DayOfWeek;
    if(daysToAdd < -3)
        daysToAdd += 7;
    if(daysToAdd > 3)
        daysToAdd -= 7;
    newDate = newDate.AddDays(daysToAdd);
    

    This always rounds to the nearest day with the same DayOfWeek.

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

Sidebar

Related Questions

I have the following SQL statement: mysql_query(SELECT * FROM `friends` WHERE friend1='$username' OR friend2='$username'
I have the following SQL query: SELECT * FROM table WHERE field_1 <> field_2
I have to following table in sql server: date | status 2009-01-01 12:00:00 OK
Assuming that I have the following T-SQL code: SELECT * FROM Foo f INNER
I have the following MS-Access SQL Table:- NAME, SUBJECT, SCORE ..and I need to
I have the following two table in SQL server 2005 DB 2- UserInfomration --->
I have the following SQL query to return all Customers who have no OrderLines
I have the following SQL table: ObjectTable -------------------------------------------------- | ID | Name | Order
I have the following SQL result set (as result of a join FWIW): A,C
I have the following table in a SQL Server 2008 database with lots of

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.