CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Dates

  1. #1
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Dates

    If I have date like "6/29/01" how do I get the date for the first day of the week (Monday)
    which in this case would be "6/25/01" using VB code.

    Kris
    Software Engineer
    Phoenix,AZ
    Kris
    Software Engineer
    Phoenix, AZ USA

  2. #2
    Join Date
    Jul 1999
    Posts
    84

    Re: Dates

    Hello,

    Weekday function returns the day of the week in numericals, i.e 1=Sunday.

    Now using the Day function get the date i.e. 29. Now get the weekday of 6/29/01. Find the difference between 6/29/01 weekday and 2 (monday).
    Subtract the difference from the day(6/29/01). That will be 4. Hence you will get the result as 6/25/01.

    Thanks
    Harini

  3. #3
    Join Date
    Jul 2000
    Location
    The Netherlands
    Posts
    26

    Re: Dates

    Using the weekday function, you can get a number that represents the weekday of the entered date. You can then use several available date functions described in the MSDN library to subtract a number of days from the date and get the first day of the week.

    mydate = date(Now) 'get the current date
    myDay = Weekday(mydate) 'get the weekday from the date
    mynewdate = date(myDate - myday) '(?)subtract the number of days to get the first day of this week.(?)



    I don't really know if that last line will work, but the Weekday function should at least give you a chance to find out the day of the week. I hope this info was useful!


  4. #4
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Dates

    Maybe this would work

    Dim datetoday As Date
    datetoday = Date
    Text1 = DateAdd("d", -1 * (Weekday(datetoday) - 2), datetoday)


    David Paulson

  5. #5
    Join Date
    Jul 2000
    Location
    The Netherlands
    Posts
    26

    Re: Dates

    You're right: it works perfectly! Just convdert the Text1 to a date, and you have full functionality with the first day of the current week. Thank you, David!


  6. #6
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: Dates

    That Works Great!!! Thanks So Much!!!

    Kris
    Software Engineer
    Phoenix,AZ
    Kris
    Software Engineer
    Phoenix, AZ USA

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