Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Excel: Add one second to a time

Tags:

time

excel

vba

I'm working with a spreadsheet with two columns, in which one of the columns is a time. I have loaded the data into a dictionary using the time as a key. I want to look up the data corresponding to a particular time (easy), and then get the next data point so that I can compare their values. The data is recorded such that one piece of data is generated every second over a period of around two hours.

My question is, does VBA in Excel have a function which can automatically add one second to a time? Or do I need to manually write one?

Update: In addition to the answers below, I have also found the "DateAdd" function useful - I suspect it depends on the version of Excel being used.

like image 803
Bridget Avatar asked Jan 16 '12 03:01

Bridget


1 Answers

you should be able to use Time(hour, minute,second) function to add a second to the time.

so to add 1 second to a date with something like Date(2012,1,16) + Time(0,0,1) which should result in a value of "2012-01-16 12:00:01 AM"

like image 75
Nathan Fisher Avatar answered Oct 05 '22 10:10

Nathan Fisher