DatabaseColumn.DateTimeValue reads a standard SQLDateTime formatted string into a DateTime object. There are times when you need greater accuracy and for this, I use the following method which also optionally allows you to set the timezone. It is an extension method which means you need to paste this into a module and its scope needs to be global.
Public Function PreciseDateTime(Extends value As DatabaseColumn, Optional tz As TimeZone) As DateTime
Var s As String = value.StringValue
Var nanoseconds As Integer = s.NthField(".", 2).ToInteger
Var dt As DateTime = DateTime.FromString(s.NthField(".", 1), Nil, tz)
Var result As New DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, Nanoseconds, tz)
Return result
End Function
Public Function PreciseDateTime(Extends value As DatabaseColumn, Optional tz As TimeZone) As DateTime
Var s As String = value.StringValue
Var nanoseconds As Integer = val("0." + s.NthField(".",2)) * 1E9
Var dt As DateTime = DateTime.FromString(s.NthField(".", 1), Nil, tz)
Var result As New DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, Nanoseconds, tz)
Return result
End Function