Getting Unixtime in VBA

  • Thread starter Thread starter Scalpel
  • Start date Start date
S

Scalpel

Hi, I'm having some trouble getting the current unix time. I see a lo
of people here try to convert from unix time to human readable time
but I actually need the unix time.

How can I get it in VBA scripting
 
J.E. McGimpsey has some notes at:
http://www.mcgimpsey.com/excel/#usingvba

One of those notes is:
If A1 contains the UNIX time value, the XL date/time is:
=DATE(1970,1,1) + A1/86400

So I put that formula in B1. (and some giant number in A1)

So to convert that back:
=(B1-DATE(1970,1,1))*86400

And got my original value back!

J.E. has some code that does the first conversion in a UDF.

He made some nice enhancements that include if it was called from a worksheet
and what your basedate (1900 or 1904) is.

If you really need code (I wouldn't), then you could use his as the shell for
yours.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top