Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Converting To Unix Timestamp, Function to convert standard time format to Unix timestamp
Galahad
post Apr 14 2005, 04:51 PM
Post #1


Neurotical Squirrel
*********

Group: [HOSTED]
Posts: 590
Joined: 4-November 04
From: Novi Sad, Vojvodina
Member No.: 2,127



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
Go to the top of the page
 
+Quote Post
iGuest
post Oct 26 2007, 07:50 PM
Post #2


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



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

-Mike
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Log Function(2)


 



- Lo-Fi Version Time is now: 7th October 2008 - 01:48 AM