Because the type of paymentRequest.TimeStamp
is Date?
(i.e. Nullable(Of DateTime)
) then you would need paymentRequest.TimeStamp.Value
to get its value, and so the code snippet should be
.Timestamp = paymentRequest.TimeStamp.Value.ToString("yyyyMMddHHmmss")
Although it is undocumented (as far as I can find), you can also use CDate
to get the date from a Date?
thus: .Timestamp = CDate(paymentRequest.TimeStamp).ToString("yyyyMMddHHmmss")
.
You may wish to avoid using an undocumented feature, as it could change without notification in later versions.
Both ways will fail with an error of
System.InvalidOperationException: 'Nullable object must have a value.'
if paymentRequest.TimeStamp.HasValue
is False
.
Perhaps confusingly, the documentation for the Nullable.ToString Method says that
The ToString property returns the string yielded by calling the ToString property of the object returned by the Value property.
however, it should be noted that this only applies to the ToString() method with no arguments.