How to convert a DB2 timestamp to datetime?

How to convert a timestamp returned from DB2 ISeries to a DateTime data type in C #?

2012-07-06 09:52:50.926145

It didn’t work for me

myEmployee.LastModified = Convert.ToDateTime(myRecord.GetString(myRecord.GetOrdinal("LASTMODIFIED")));
+5
source share
2 answers

DateTime.Parse?

DateTime result = DateTime.Parse("2012-07-06 09:52:50.926145");

It works, really.

+5
source

You can do it with DateTime.TryParse()

DateTime date;
DateTime.TryParse("2012-07-06 09:52:50.926145", out date);

In your case

DateTime date,
DateTime.TryParse(myRecord.GetString(myRecord.GetOrdinal("LASTMODIFIED")), out date);
+1
source

All Articles