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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:09:58+00:00 2026-05-21T04:09:58+00:00

Dim x As Date x = 5/26/2011 Dim whichweek As Double = x.DayOfYear /

  • 0
    Dim x As Date
    x = "5/26/2011"
    Dim whichweek As Double = x.DayOfYear / 7
    Dim whichday As Integer = x.DayOfWeek       

using this information could i get a certain week last year and a certain day of that week and use the date

This is return 4/10/2010 instead of 4/5/2010 and 5/26/2011 is returning 5/27/2011

 Public Shared Function GetWeekNumber(ByVal dtPassed As DateTime) As Integer
    Dim ciCurr As CultureInfo = CultureInfo.CurrentCulture
    Dim weekNum As Integer = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)
    Return weekNum
End Function

 Dim x As Date
    x = "4/04/2011"
    Dim whichweek As Integer = GetWeekNumber(x.Date)
    Dim whichday As Integer = x.DayOfWeek

    Dim offset As New TimeSpan(whichweek * 7 + whichday, 0, 0, 0)
    Dim sameWeekLastYear = New DateTime(x.Year - 1, 1, 1) + offset

    Label9.Text = sameWeekLastYear
  • 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-21T04:09:59+00:00Added an answer on May 21, 2026 at 4:09 am

    To get the same weekday in the same week of the previous year, you can use something like this:

    Dim offset As New TimeSpan(whichweek * 7 + whichday, 0, 0, 0)
    Dim sameWeekLastYear = New DateTime(x.Year - 1, 1, 1) + offset
    

    (But as Hans said in the comments, your calculation of the week is unfortunately wrong.)

    However, don’t use a string to initialise a date. In fact, your code shouldn’t even compile. You should enable Option Strict to make the compiler check for errors more strictly.

    To initialise a date from a constant, use the date literal syntax:

    Dim date = #5/26/2011#
    

    Or, if you really need to read a string because you’re reading a file or getting user input, use the DateTime.Parse method to parse the string properly.

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

Sidebar

Related Questions

Dim dtmStart As Date, dtmEnd As Date, dblDuration As Double dtmStart = 1900/01/01 08:10:00
I've got a date variable that looks like this: Dim LogDate As Date =
Dim i as integer For i = 0 to 365 sqlinsert.InsertCommand=insert into cashdate (date)
dim dataType as String toolTip=Marks And Number[String] I want to get the [String] alone.
I get this error when attempting to debug my form, I cannot see where
I want to get the difference of date from Two TextBox say to and
SELECT NON EMPTY {[Measures].[Page Views]} ON COLUMNS, NON EMPTY { Crossjoin({[Date Dim.Weekday Hierarchy].[Weekday].Members}, {[Time
i am using visual stdio 2008 and sql server 2005 dim selectquery = SELECT
I have a date value (e.g. 2011-04-11 07:45:00.000) which I am pulling from my
I am trying to truncate the seconds part from the current Date Dim nowTime

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.