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

Thread: Date Functions

  1. #1
    Join Date
    Jun 1999
    Location
    Texas
    Posts
    119

    Date Functions

    I am assigning the current date to a text box, however, I want to always subtract three days if the day falls on a "Monday". I have the days of the week all worked out, but I can't seem to subtract the amount of days that I need.

    If (ResultDate = "Monday") then
    MyTextBox.Text = Today - 3
    End If



    Of course the above does not work, but that is the basic problem I am having. If anyone has an idea please let me know.
    Thanks


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Date Functions


    mytextbox.text = DateAdd("d", Now, -3)





  3. #3
    Guest

    Re: Date Functions

    The function should actually be

    Mydate = Format$(DateAdd("d", -3, Now), "dddd")



    you can use format$ to format a date anyway you like check te help files.


  4. #4
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: Date Functions

    The WeekDay Function returns an integer representing the day of week referenced by a date.

    dtMyDate = CDate(text1.Text) 'get date From Text Box
    iDayOfWeek = WeekDay(dtMyDate) 'Ask for the day of week

    If iDayOfWeek = 2 then 'If it's Monday
    dtMyDate = dtMyDate - 3 'Subtract 3 days
    text1.Text = Format(dtMyDate, "MM/DD/YYYY")
    End If





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