Question : Convert an 8 byte VB6 date to C# DateTime

I have an old program that converts a VB6 date into 8 bytes and sends it over a network. I can't change the old program so I have to live with the 8 bytes that I get. Here's the code that converts the VB6 date into 8 bytes:


Private Sub Date2Bytes(aBytes() As Byte, lPtr As Long, dValue As Date)
    Dim sTmp As String
    Dim x As Long
   
    On Error GoTo ErrorHandler
    'First change it to a string
    sTmp = Space(8)
    CopyMemory ByVal sTmp, dValue, 8
   
    'Put the string into the bytes
    For x = 0 To 7
        aBytes(x + lPtr) = Asc(Mid(sTmp, x + 1, 1))
    Next
    Exit Sub

ErrorHandler:
    Err.Clear
End Sub


As an example, the above code produces these 8 bytes [E8 B4 81 8E B1 B4 E3 40] for the date value of [6/28/2010 1:10:03 PM].

When I receive the 8 bytes in my program (Visual Studio 2005, C#) I have to convert them back to a C# DateTime value. Any idea how I do this?

Answer : Convert an 8 byte VB6 date to C# DateTime

try convert the hex to binay

and use DateTime.FromBinary

http://msdn.microsoft.com/en-us/library/system.datetime.frombinary.aspx

I hope it will work  good luck

Random Solutions  
 
programming4us programming4us