DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  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,652
    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 03:24 PM.

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,652
    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-30-2008, 11:47 PM
  2. VB.NET White Papers posted this week
    By Yair Alan Griver [MSFT] in forum .NET
    Replies: 0
    Last Post: 01-24-2002, 04:55 PM
  3. XML Startkabel update week 8 2001
    By Haitian Ning in forum XML
    Replies: 0
    Last Post: 02-20-2001, 05:04 PM
  4. SQL for 'week beginning;'
    By Stephen Travis in forum Database
    Replies: 0
    Last Post: 09-01-2000, 12:06 PM
  5. Replies: 1
    Last Post: 05-04-2000, 02:44 AM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links