UNIX Timestamp Visual Basic 6

December 5, 2009

Time() Function

Since I started programming in PHP, after Visual Basic, I started to rely on some of the features available with PHP. One of those was the Time() function.

Since I don't know of any function that does this in Visual basic, I made this "wrapper" function to calculate with less code.

While I know this works for Visual Basic 6 Enterprise Edition, I'm not sure about earlier versions of Visual Basic. Please comment with your findings.

I do not believe this works with .NET-based languages (Visual Studio 2003 through 2010).
Option Explicit
Dim DateTime As String
Private Function Time(ByVal DateTime As String)
Time = DateDiff("s", "01/1/1970 12:00:00 AM", DateTime)
End Function

Using this function is relatively simple:
Private Sub Form_Load()
Form1.Caption = Time(Now)
End Sub

"Now" is a Visual Basic Constant that contains a current timestamp (like this: 12/04/2009 11:57:00 AM). This will return the current timestamp as Form1's caption property.

You can also insert any (properly formatted) time into this function and get a result. You may get an error using this function if you don't call it / pass variables correctly. I didn't error-check it so you can debug it easier during development.

Proper formats:

mm/dd/yy
mm/dd/yyyy
mm/dd/yyyy hh:mm:ss ap
Try out your specifc requirements, they may work.

Thanks for reading, please leave a comment below if you liked this article

Name:

No comments yet! Be the first!