# Adding seconds to a date value

Dim StartDate as date
StartDate=Now

how can i add 1 second to StartDate?
###### Who is Participating?

Commented:

From the help:

Returns a Variant (Date) containing a date to which a specified time interval has been added.

Syntax

The DateAdd function syntax has these named arguments:

Part      Description
interval      Required. String expression that is the interval of time you want to add.
number      Required. Numeric expression that is the number of intervals you want to add. It can be positive (to get dates in the future) or negative (to get dates in the past).
date      Required. Variant (Date) or literal representing date to which the interval is added.
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
Remarks

You can use the DateAdd function to add or subtract a specified time interval from a date. For example, you can use DateAdd to calculate a date 30 days from today or a time 45 minutes from now.
To add days to date, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").
The DateAdd function won't return an invalid date. The following example adds one month to January 31:

In this case, DateAdd returns 28-Feb-95, not 31-Feb-95. If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.

If the calculated date would precede the year 100 (that is, you subtract more years than are in date), an error occurs.

If number isn't a Long value, it is rounded to the nearest whole number before being evaluated.
0

Author Commented:
dim sDate as date
MsgBox sDate & "   :   " & sDate + 0.00001

that works... will it always?... i was just trying things out
0

Commented:
Internally dates are stored as a double. The integer part is the date and the decimal portion is the time. Adding an appropriately small value will work - sort of. If you want accurate time computations, use the functions provided for that purpose.

M
0

Commented:
Option Explicit

MsgBox ("Now + 1 seconds: " & DateAdd("s", 1, Now) & ("Now: " & DatePart("s", Now)))

End Sub
0

Author Commented:
Here is what happens. I have a timer that fires every second. ... Just to keep track of time. And i use datediff to see howmany seconds have passed. I get the diff between now and a stored date. I want to be able to pause the time keeping. I have a date pausetime that is the pasue time and i thought i could add the difference between pausetime and now to starttime to move start time along with the real time to make it appear that the clock was paused..i used this code..

StartTime = DateAdd("s", DateDiff("s", PauseTime, Now), StartTime)

.... but it doesn't work...
0

Commented:

Use DataPart function to get the part of the date or time...

MsgBox ("Now + 1 seconds: " & DateAdd("s", 1, Now) & vbTab & ("Second Now : " & DatePart("s", Now)))
End Sub
0

Author Commented:
DateDiff("s", PauseTime, Now)... this part is right..i can watch it incriment in seconds....
0

Commented:
You want to measure elapsed time or real time? Elapsed time is simple, make a global or a static var in your timer routine and shut it off and back on. Real time is same-same except you display NOW instead of doing date computations.

M
0

Author Commented:
that is just what i needed. I was adding 1 second after the first second and then 2 seconds after the 2nd second... instead of 1 each time. Thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.