ONE week back based today


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: ONE week back based today

  1. #1
    Join Date
    Mar 2005
    Posts
    37

    ONE week back based today

    Based the today date wath is the date of moonday and freeday of first one back week?

    for example:

    today is 27/03/2012

    monnday 19/03/2012
    fryday 23/03/2013

    ....

    today is 12/03/2012

    monnday 05/03/2012
    fryday 09/03/2013

    how to calculate this steep of dates?

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Try
    Code:
    Private Sub Command1_Click()
    MsgBox DateAdd("d", -7, Date)
    End Sub
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Mar 2005
    Posts
    37
    [QUOTE=Hack;532433]Try
    Code:
    Private Sub Command1_Click()
    MsgBox DateAdd("d", -7, Date)
    End Sub
    [/QUOTE

    But you code return a TUESDAY and not a MONDAY (day init of one back week)

    in other case i ned to have also the FRIDAY date of one back week... how to?
    Last edited by luca90; 03-27-2012 at 04:24 PM.

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Try these functions. Both will find the last Friday and last Monday based on the date passed to it
    Code:
    Option Explicit
    
    Private Function FindLastMonday(ByVal pintDayOfWeek As VbDayOfWeek, ByVal pdteDateToCheckAgainst As Date) As Date
        Do
            pdteDateToCheckAgainst = DateAdd("d", -1, pdteDateToCheckAgainst)
        Loop Until Weekday(pdteDateToCheckAgainst) = pintDayOfWeek
        FindLastMonday = pdteDateToCheckAgainst
    
    End Function
    
    Private Function FindLastFriday(ByVal pintDayOfWeek As VbDayOfWeek, ByVal pdteDateToCheckAgainst As Date) As Date
        Do
            pdteDateToCheckAgainst = DateAdd("d", -1, pdteDateToCheckAgainst)
        Loop Until Weekday(pdteDateToCheckAgainst) = pintDayOfWeek
        FindLastFriday = pdteDateToCheckAgainst
    
    End Function
    
    Private Sub Command1_Click()
    Text1.Text = FindLastFriday(vbFriday, Format(Now, "mm/dd/yyyy"))
    Text2.Text = FindLastMonday(vbMonday, Format(Now, "mm/dd/yyyy"))
    End Sub
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 0
    Last Post: 10-31-2008, 12:47 AM
  2. VB.NET White Papers posted this week
    By Yair Alan Griver [MSFT] in forum .NET
    Replies: 0
    Last Post: 01-24-2002, 05:55 PM
  3. XML Startkabel update week 8 2001
    By Haitian Ning in forum XML
    Replies: 0
    Last Post: 02-20-2001, 06:04 PM
  4. SQL for 'week beginning;'
    By Stephen Travis in forum Database
    Replies: 0
    Last Post: 09-01-2000, 01:06 PM
  5. Replies: 1
    Last Post: 05-04-2000, 03:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center