Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Timestamp to datetime on C#

I have the following column on my SQL table:

RECORDTIMESTAMP
0x000000000005B2A4
0x000000000005B2A5
0x000000000005B2A6

And I need to return this values on my C# program. This atributte is declared like this:

public DateTime? RecordTimeStamp{ get; set; }

And my method to get is this one:

RecordTimeStamp = DateTime.Parse(row["RecordTimeStamp"].ToString()),

The error message is the following:

  "The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.",

I also tried to declare the atribbute as string but it didn't worked also.

Any Ideas on this?

like image 650
pedro lopez Avatar asked Feb 12 '26 18:02

pedro lopez


1 Answers

A common misconeption here: Timestamp is not actual a time.

It was a miss-naming. That is why it was renamed to ROWVERSION half a dozen versions ago. Timestamp was only still used as Alias, with a clear "deprecated" marker. From https://learn.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql:

timestamp is the synonym for the rowversion data type and is subject to the behavior of data type synonyms. In DDL statements, use rowversion instead of timestamp wherever possible. For more information, see Data Type Synonyms (Transact-SQL).

The Transact-SQL timestamp data type is different from the timestamp data type defined in the ISO standard.

Note

The timestamp syntax is deprecated. This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

like image 142
Christopher Avatar answered Feb 15 '26 06:02

Christopher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!