ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting Unixtime in VBA (https://www.excelbanter.com/excel-programming/299379-getting-unixtime-vba.html)

Scalpel

Getting Unixtime in VBA
 
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

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

Getting Unixtime in VBA
 
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.


"Scalpel <" wrote:

Hi, I'm having some trouble getting the current unix time. I see a lot
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?

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson



All times are GMT +1. The time now is 10:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com