Jump to content
xisto Community
Sign in to follow this  
Galahad

Converting To Unix Timestamp Function to convert standard time format to Unix timestamp

Recommended Posts

I don't know how many of you are familiar with IRC development, but all time/date information are saved in unix time stamp format. Unix timestamp is number of seconds elapsed, since 1st january 1970. Unix timestamp is also used in phpBB forums, and possibly in other bulletin boards. It is very convenient for manipulation, mathematical calculations, and other things...

Use these functions to work with Unix time stamps (this is fully working code, just copy/paste it):

Option ExplicitPrivate Type SystemTime        wYear As Integer        wMonth As Integer        wDayOfWeek As Integer        wDay As Integer        wHour As Integer        wMinute As Integer        wSecond As Integer        wMilliseconds As IntegerEnd TypePrivate Type TIME_ZONE_INFORMATION        Bias As Long        StandardName(32) As Integer        StandardDate As SystemTime        StandardBias As Long        DaylightName(32) As Integer        DaylightDate As SystemTime        DaylightBias As LongEnd TypePrivate Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As LongPrivate Declare Function timeGetTime Lib "winmm.dll" () As LongPublic Function FromUnixTime(ByVal sUnixTime As Long) As DateDim NTime As Date, STime As DateDim TZ As TIME_ZONE_INFORMATIONSTime = #1/1/1970#NTime = DateAdd("s", sUnixTime, STime)GetTimeZoneInformation TZNTime = DateAdd("n", -TZ.Bias, NTime)FromUnixTime = NTimeEnd FunctionPublic Function ToUnixTime(ByVal STime As Date) As LongDim NTime As Date, sUnix As Date, sUnixTime As LongDim TZ As TIME_ZONE_INFORMATIONsUnix = #1/1/1970#GetTimeZoneInformation TZNTime = DateAdd("n", TZ.Bias, STime)sUnixTime = DateDiff("s", sUnix, NTime)ToUnixTime = sUnixTimeEnd Function

I hope this helped someone :o

Share this post


Link to post
Share on other sites
Excellent FunctionConverting To Unix Timestamp

Great function, took me hours to find this. There doesn't seem to be many posts over the net on functions this advanced for vba.

Thx 

-reply by webCrafter

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.