CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 1999
    Location
    France
    Posts
    29

    Date of the first day of a week

    Hi everybody

    I want to know the date of the first day of a week.
    Example: I choose a date : the 5th of MAY 2003.
    I can have the week (between 1 and 52)
    But I want the date of the first day of this week.
    I can get the day (monday, tuesday...) and if I know how many days there are in the month I can move backward until the first day.
    Is there a method faster and easier than this one???

    Fzz


  2. #2
    Join Date
    Jan 2000
    Posts
    2

    Re: Date of the first day of a week

    you need to deduct the day of the week from the date and this gives you the first day of the week for that date.

    try this
    [vbcode
    Dim lDay As Long
    If IsDate(Text1.Text) Then
    Text2.Text = (CDate(Text1.Text)) - (Weekday(Text1.Text) - 1)
    End If

    [/vbcode]

    hope it helps

    jonathan



  3. #3
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Date of the first day of a week

    assuming date is in a variable "dtIn" then:

    DATEadd("d",0-((datepart("w",dtIn))-1), dtIn)



    is about as short as I can get it.

    HTH,
    Duncan

    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  4. #4
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: Date of the first day of a week

    If you use DTPicker control for the input of the date value, then check out the property "DayOfWeek". Maybe this helps.


    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

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

Featured