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

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Posts
    132

    Adding time to Now()

    I am hoping somone can help. I am making a small reminder program and want to add a certain amount of time to the current date and time. For example I might want to know the date and time of Now + 3 hours. Is there an easy way of doing this so that it will rollover after midnight if applicable? Any tips will be appreciated.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Adding time to Now()

    Use the DateAdd() function with Now as one of the parameters. You will find info on all the different params in your online help

    Syntax

    DateAdd(interval, number, date)

    Settings

    The interval argument has these settings:

    Setting Description
    yyyy Year
    q Quarter
    m Month
    y Day of year
    d Day
    w Weekday
    ww Week
    h Hour
    n Minute
    s Second



    Example:
    Code:
    Private Sub Command1_Click()
    
    Dim TargetTime As Date
    
    TargetTime = DateAdd("h", 3, Now())
    
    MsgBox TargetTime
    
    End Sub

  3. #3
    Join Date
    Aug 2004
    Posts
    132

    Re: Adding time to Now()

    Thank you so much, exactly what I need.

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