4

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 2

5

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.

Sign up to request clarification or add additional context in comments.

8 Comments

then what is the use of timestamp datatype in SQL and why we use this?
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.
Then can i convert the date to timestamp using to-timestamp('gps_timestamp','YYYY-MM-DD HH24:MI:SS.FF'), in sql
@user285oo6 by "timestamp", do you mean a 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" ?
datetime the one which is accurate to the nano seconds
|
2

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.

2 Comments

If we want to show timestamp value on aspx page then how we can show this value???
@Gaurav Agrawal - the timestamp data type does not usually contain data valuable for display, as it is usually just auto generated binary (somewhat random) data. If you need to store a date data type, use the datetime datatype in SQL. However, if you must display this data, you will need to convert the data to a string using something like Convert.ToBase64String()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.