I am using LINQ and in my database Tstamp fileld with Timestamp datatype. Now i want to fetch data from SQL by using LINQ query and it returns me Tstamp datafield value in System.Data.Linq.Binary datatype. Now i want to convert this Binary datatype value in Datetime format but how?
2 Answers
DateTime != timestamp
A SQL timestamp is a monotonically increasing number, expressed as binary. Not time. Nothing to do with time, except that they both roll ever-forwards. Which is why timestamp (as a keyword) is now deprecated (as confusing), and replaced with rowversion.
You cannot get time from a timestamp. If you want the time, store the time as datetime.
8 Comments
timestamp (and rowversion, which are synonymous) are used to perform optimistic concurrency and change detection, since you can easily check via a single field if anything has changed. That is because any change to that record automatically changes the timestamp/rowversion to a new (higher) number.datetime? or do you mean a rowversion? Both are referred to as "timestamp"s, but they are very different things. What do you mean by "timestamp" ?The SQL timestamp is not actually a datetime data type. It is an auto-generated binary data type used for versioning your row. Therefore, it cannot be converted to a datetime value in C#.
See the MSDN article for more info.