Results 1 to 9 of 9

Thread: Dates

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Dates

    Hey,

    How would I calculate the Last Week of today's date?
    I don't need the last 7 days, but the last week.

    Thanks,
    Don't anthropomorphize computers -- they hate it

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Dates

    As in.. just subtract 7 days??? If so, then use the .Subtract method of the Date class...
    Code:
    'todays date       
    Dim MyDate As Date = Date.Now 
    'below, subtracts 7 days from MyDate
    Dim OldDate As Date = MyDate.Subtract(New TimeSpan(7, 0, 0, 0))
    'Displays date from a week ago...
    MessageBox.Show(OldDate.ToShortDateString)

  3. #3

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Re: Dates

    no, I know how to subtract 7 days.
    I want the dates of last week. (Monday to Sunday of last week)
    Don't anthropomorphize computers -- they hate it

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Dates

    Then just loop
    Code:
            Dim MyDate As Date = Date.Now
            For I As Integer = 1 To 7 Step 1
                Dim OldDate As Date = MyDate.Subtract(New TimeSpan(I, 0, 0, 0))
                MessageBox.Show(OldDate.ToShortDateString)
            Next
    Or do you want the first full monday to sunday...? And only monday to sunday?

    **EDIT - had -1 instead of 1...
    Last edited by gigemboy; Feb 4th, 2006 at 12:22 AM.

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Dates

    Here's how to get the first full Moday to Sunday of the previous week...
    Code:
            Dim MyDate As Date = Date.Now
            For J As Integer = 7 To 1 Step -1
                Dim OldDate As Date = MyDate.Subtract(New TimeSpan(J + MyDate.DayOfWeek - 1, 0, 0, 0))
                MessageBox.Show(OldDate.ToShortDateString)
            Next

  6. #6

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Re: Dates

    What I need is to know the dates of last week.
    If today is 4th of February, the dates I want are January 23 - 29.
    That would be last week.
    Don't anthropomorphize computers -- they hate it

  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Dates

    Then my last post above should do it

  8. #8

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Re: Dates

    hehe, we posted at teh same time. the second one works fine. thanks a lot.
    Don't anthropomorphize computers -- they hate it

  9. #9
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Dates

    On a side note, to get the actual enumeration value that states "Monday", etc instead of the numbers, you can try something like this in the messagebox code above...
    Code:
    'displays the value as "Monday, 01/23/2006"
    MessageBox.Show(DayOfWeek.GetName(GetType(DayOfWeek), OldDate.DayOfWeek) & ", " & OldDate.ToShortDateString)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width