Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Matilda Hughes   on Sep 07 In MS Office Category.

  
Question Answered By: Marta Kim   on Sep 07

I "assume" when you say "the current time  in seconds" you're referring
to the current  time of day, not the current date/time.
There are several ways to accomplish this.
Both use (as described before) the NOW() function to return  the
current date and time.

One technique would be to use the Format() function to strip off
the Hours, Minutes and Seconds, multiplying the Hours 3600 seconds
per hours, Minutes by 60 second pr minute and adding them all together
will give you the total seconds since Midnight.

If you chose to, you can remove the Integer portion of the NOW result
and what you have left is the decimal representation of the fractional
part of the day. (EXACTLY 12:00 noon would be .5000) You can round
this to any number of digits to achieve a nearly unique  identifier.

Try:

Dim ThisDate
ThisDate = Now
MsgBox ThisDate & Chr(13) & _
Format(ThisDate, "h") * 3600 + _
Format(ThisDate, "N") * 60 + _
Format(ThisDate, "s") & Chr(13) & _
Round(ThisDate - Int(ThisDate), 6)

and see what they look like.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on return time in seconds in VBA? Or get search suggestion and latest updates.


Tagged: