Nov 21, 2009

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

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > VB Programming

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

Galahad
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):

CODE
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 smile.gif

 

 

 


Comment/Reply (w/o sign-up)

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

-Mike

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : converting, unix, timestamp, function, convert, standard, time, format, unix, timestamp

  1. Log Function
    (2)


      Looking for converting, unix, timestamp, function, convert, standard, time, format, unix, timestamp
Similar
Log Function

Searching Video's for converting, unix, timestamp, function, convert, standard, time, format, unix, timestamp
See Also,
advertisement


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

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com