Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Converting To Unix Timestamp


2 replies to this topic

#1 Galahad

    Neurotical Squirrel

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 590 posts
  • Gender:Male
  • Location:Novi Sad, Vojvodina
  • Interests:Programming, Hardcore dance/Trance/House music. Girls, girls and more girls ;) ... In short, everything youg people like, I like :D Oh yeah, and dont't forget politics :)
  • myCENT:48.25

Posted 14 April 2005 - 04:51 PM

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 Explicit

Private 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 Integer
End Type
Private 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 Long
End Type
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Public Function FromUnixTime(ByVal sUnixTime As Long) As Date
Dim NTime As Date, STime As Date
Dim TZ As TIME_ZONE_INFORMATION
STime = #1/1/1970#
NTime = DateAdd("s", sUnixTime, STime)
GetTimeZoneInformation TZ
NTime = DateAdd("n", -TZ.Bias, NTime)
FromUnixTime = NTime
End Function

Public Function ToUnixTime(ByVal STime As Date) As Long
Dim NTime As Date, sUnix As Date, sUnixTime As Long
Dim TZ As TIME_ZONE_INFORMATION
sUnix = #1/1/1970#
GetTimeZoneInformation TZ
NTime = DateAdd("n", TZ.Bias, STime)
sUnixTime = DateDiff("s", sUnix, NTime)
ToUnixTime = sUnixTime
End Function

I hope this helped someone :o

#2 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 26 October 2007 - 07:50 PM

Would like to see this for VBSCRIPT =) That would really help quite a bit

-Mike

#3 iGuest

    Hail Caesar!

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,876 posts
  • Interests:Trap17 Free Web Hosting, No Ads

Posted 02 January 2010 - 01:43 AM

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




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users