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 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

I'm using the following code to display an arabic date: Dim dtFormat As DateTimeFormatInfo
1 Dim x as Integer? = Nothing 2 If x = Nothing Then 3
I can do this: Dim fso As New FileSystemObject or I can do this:
I have this code: Dim pathString As String = HttpContext.Current.Request.MapPath(Banking.mdb) Dim odbconBanking As New
I have this: Dim myTemp As String myTemp = System.DateTime.Now().ToString(MMMddyyyy_HHmmss) & .pdf System.IO.File.Copy(myFile, c:\
We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
In VB6 you can do this: Dim a As Variant a = Array(1, 2,
I would like to get a 'due' or predicted inspection date based on alternating
How can I pick out files using todays date? I have files that have
i am using visual stdio 2008 and sql server 2005 dim selectquery = SELECT

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.