Getting Unixtime in VBA

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
 
D

Dave Peterson

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.
 
Top