none
Convert SQL timestamp to DateTime

    Question

  • Hi,

       We have a table in SqlServer 2008 with a column type TimeStamp and contain value such as 0x00000000656AC51F.

    I tried to convert it to DataTime but get an exception: "Value to add was out of range."

     

    what I did is:

    byte [] tTimeStamp = (byte [])row["TimeStamp"]
    long longVar = BitConverter.ToInt64(value,0);
     DateTime date = new DateTime(1980, 1, 1).AddMilliseconds(longVar);
    

    how it should be done?

    Thanks

    Markos.


     

    Thursday, July 28, 2011 8:50 AM

Answers

  • Hi

    TimeStamp datatype is n sqlserver does not really represent DateTime...It's a just increamental unique number

    check more to know

    http://msdn.microsoft.com/en-us/library/ms182776(v=SQL.90).aspx


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    • Marked as answer by Markos_King Thursday, July 28, 2011 9:57 AM
    Thursday, July 28, 2011 9:08 AM
  • its not a stupid decision at all. perfectly valid. it seems that you are not understanding some technology and its uses and what should be used when.

    learn more about timestamp:

    http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx

     

    quote:

    This tracks a relative time within a database, not an actual time that can be associated with a clock.

    ..

    You can use the timestamp column of a row to easily determine whether any value in the row has changed since the last time it was read. If any change is made to the row, the timestamp value is updated. If no change is made to the row, the timestamp value is the same as when it was previously read.

     

    i.e - not with DateTime.


    C# MVP (2007-2010) MS Vendor - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
    Thursday, July 28, 2011 10:01 AM
    Moderator

All replies

  • Hi

    TimeStamp datatype is n sqlserver does not really represent DateTime...It's a just increamental unique number

    check more to know

    http://msdn.microsoft.com/en-us/library/ms182776(v=SQL.90).aspx


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
    • Marked as answer by Markos_King Thursday, July 28, 2011 9:57 AM
    Thursday, July 28, 2011 9:08 AM
  • But what we need this if it is not the time!

    Stupid decision!, as some of Microsoft's decisions!

     

    Thanks anyway!

    Thursday, July 28, 2011 9:58 AM
  • its not a stupid decision at all. perfectly valid. it seems that you are not understanding some technology and its uses and what should be used when.

    learn more about timestamp:

    http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx

     

    quote:

    This tracks a relative time within a database, not an actual time that can be associated with a clock.

    ..

    You can use the timestamp column of a row to easily determine whether any value in the row has changed since the last time it was read. If any change is made to the row, the timestamp value is updated. If no change is made to the row, the timestamp value is the same as when it was previously read.

     

    i.e - not with DateTime.


    C# MVP (2007-2010) MS Vendor - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
    Thursday, July 28, 2011 10:01 AM
    Moderator
  • Timestamp define to save the current time point (row modification), so what I can do with a number that don't tell me anything about the time!, the time when record modified?

    the word Time inside the timestamp was for purpose.

    They can use counter for the change not timeStamp, it's nothing about technology, Timestamp used for count CPU tickes (usually used with reference of starting time), when Microsoft add it to database, it was to sign the last time it was modified, otherwise the name must be changed, for example: ChangeCounter.

    But as usually, they do whatever they want!

    Thursday, July 28, 2011 10:20 AM
  • http://connect.microsoft.com for any feedback or suggestions.

    however again, you need to read the documentation and understand how it works and it uses. It has been there for many years and no one has complained about it...


    C# MVP (2007-2010) MS Vendor - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
    Thursday, July 28, 2011 10:33 AM
    Moderator