Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get todays date & previous & next day

    VBA - Excel

    I remember someone posting issue re code for obtaining todays date, then working out next day or previous day.

    I did a seach on forum but search didnt return the result I was looking for.
    It may have been posted on previous forum before format changed.(& which you cant search old forum).
    Does anyone have this thread or bit of code?

    I would much appeciate it
    Thanks Diana

  2. #2
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get todays date & previous & next day

    Try:
    <pre>Cells(1, 1) = Date - 1
    Cells(2, 1) = Date
    Cells(3, 1) = Date + 1
    </pre>

    which should write
    Yesterday's date
    Today's date
    Tomorrow's date

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Get todays date & previous & next day

    Or, if you need to manipulate the dates further, use the DateAdd function:

    Sub testDates()
    Dim datYesterday As Date, datTomorrow As Date
    datYesterday = DateAdd("d", -1, Date)
    datTomorrow = DateAdd("d", 1, Date)
    MsgBox "Yesterday was " & datYesterday & vbCrLf & _
    "Tomorrow will be " & datTomorrow
    End Sub

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get todays date & previous & next day

    or DON'T use the DateAdd function ...
    <pre>Public Function strYesterDate() As String
    ' Procedure : strYesterDate
    ' Description: Return a string value of yesterday's date.
    ' By: Chris Greaves Inc.
    ' Inputs: None
    ' Returns: None
    ' Assumes: Nothing
    ' Side Effects: None.
    ' Tested: By the calls shown below
    strYesterDate = Format((Date - 1), "dddd, MMMM dd, yyyy")
    'Sub TESTstrYesterDate()
    'MsgBox strYesterDate
    'End Sub
    End Function
    </pre>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •