472,360 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,360 software developers and data experts.

Conversion of .NET DateTime to SQL datetime via VarBinary

I am doing some experimenting with serialization (for use with Service
Broker) and I am having a problem converting from a .NET DateTime (in the
client application) to a SqlDbType.VarBinary (as passed to the stored
procedure VARBINARY(MAX)) and then finally back to a valid DATETIME in Sql
Server. It seems I have tried everything, but I always get an error when
trying to convert the hex value representation of the byte array to a valid
DATETIME in SQL. Any help appreciated.

So, it would be something like DateTime.Now -SqlDbType.VarBinary ->
DATETIME

Mar 23 '07 #1
1 2556
Why not send the date across as a SqlDateTime? It would alleviate your issue
and it is still serializable. If you are not storing as varbinary, why
transport via this representation.

As for how to pull from varbinary, I would have to look at how datetime is
represented in binary format. It is possible you will have to go bit by bit
(or byte by byte) to make sense of the datetime. I am sure you can
reassemble, but you will have to create the calculation. Most likely, the
binary data is a character by character representation, in bytes, which
means you will have to pull the date back out, as a string, and then
translate. Once you conquer this, you can make your own translation method
to convert. As soon as .NET 3.5 Framework is out, you could make this an
extension method.

But, we come back to the why? Why transfer as varbinary when SqlDateTime is
serializable?

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
"Karch" <no****@absotutely.comwrote in message
news:eE**************@TK2MSFTNGP05.phx.gbl...
>I am doing some experimenting with serialization (for use with Service
Broker) and I am having a problem converting from a .NET DateTime (in the
client application) to a SqlDbType.VarBinary (as passed to the stored
procedure VARBINARY(MAX)) and then finally back to a valid DATETIME in Sql
Server. It seems I have tried everything, but I always get an error when
trying to convert the hex value representation of the byte array to a valid
DATETIME in SQL. Any help appreciated.

So, it would be something like DateTime.Now -SqlDbType.VarBinary ->
DATETIME
Mar 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
0
by: Sanju | last post by:
Dear All, I have written a stored procedure which returns a Varbinary column from MS SQl Server 7 database. I tried converting the same into Varchar but this will not work in the database. I...
4
by: Kiran | last post by:
Hi Folks, Please advise me on the conversion of EpochSeconds to DD-MMM-YYYY format in c#. given are the few examples. 1093128564 1093128537 1093128419
8
by: Vinod | last post by:
Hi, I have a stored procedure which expects a varbinary datatype. How can i pass a varbinary datatype from asp.net directly to the stored procedure. I tried using the Convert function in Sql...
11
by: Tim | last post by:
Hi, I am trying to do something simple. Convert a string date to datetime but it is not working and is giving me a baffling error! System.Convert.ToDateTime("Jan 30, 2006")...
3
by: moni | last post by:
Hi, I wanted to convert a time value in the form of time_t into a readable form in C# or vice versa, in order to be able to subtract two time values and give the result in msecs. eg. I...
0
by: =?Utf-8?B?RGVuaXMgU29oZXQ=?= | last post by:
Hi all, I've created a new project to test ObjectDataSource component. I've just added a new objectdatasource, configured it (linked to a table) etc ... It works fine on localhost, i can...
5
by: Ivan Velev | last post by:
Hello, Minimal example below - it gives me different output if I comment / uncomment the extra time.mktime call - note that this call is not related in any way to main logic flow. When...
1
Manikgisl
by: Manikgisl | last post by:
But the problem is we have dates in Varchar instead Datetime While Converting Varchar To Datetime All four formats are unable to Convert ie select Convert(Datetime,'18-11-2008 2:35:19...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.