Dim dateTest As Date = Now
Dim i As Long
Dim b(8) As Byte
i = dateTest.ToBinary() ' here we have converted
our date into long
b(0) = (i >> (8 * 0)) And &HFF ' extract out the bytes
b(1) = (i >> (8 * 1)) And &HFF
b(2) = (i >> (8 * 2)) And &HFF
b(3) = (i >> (8 * 3)) And &HFF
b(4) = (i >> (8 * 4)) And &HFF
b(5) = (i >> (8 * 5)) And &HFF
b(6) = (i >> (8 * 6)) And &HFF
b(7) = (i >> (8 * 7)) And &HFF
' here we can save our b() in database
' now we are again trying converting the long into date
' suppose we have read the b() from database
Dim dv As Long = 0 ' converting bytes into
long
dv = dv Or (CLng(b(0)) << (8 * 0))
dv = dv Or (CLng(b(1)) << (8 * 1))
dv = dv Or (CLng(b(2)) << (8 * 2))
dv = dv Or (CLng(b(3)) << (8 * 3))
dv = dv Or (CLng(b(4)) << (8 * 4))
dv = dv Or (CLng(b(5)) << (8 * 5))
dv = dv Or (CLng(b(6)) << (8 * 6))
dv = dv Or (CLng(b(7)) << (8 * 7))
Dim newdate As Date
newdate = Date.FromBinary(dv) ' converting long into
date
Debug.Print(dateTest)
Debug.Print(newdate)
On Sep 17, 6:35 am, Benj Nunez <[EMAIL PROTECTED]> wrote:
> Hello experts,
>
> I was given a task to retrieve (copy) a date entry (a varchar) in a
> DB2 database. Once I get it into my app, I will convert it to a date
> first to test it if it's a valid date (e.g. using
> DateTime.ParseExact).
>
> My problem is, I am required to save (paste) this to a SQL Server
> table. There's a field called
> "PROCESSED_DATE" in there with a data type of "binary(8)". I was
> expecting that the
> data type would be "Date/Time". But that isn't the case.
>
> My question is, how do I save a literal date to a field that is a
> binary(8) data type, instead of the normal DateTime data type. Any
> ideas?
>
> Thank you in advance.
>
> Benj
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---