Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign a DateTime to Nullable<DateTime> in F# [duplicate]

I have some F# code where I need to update a field in a database record. I am using the Type Provider for SQL. The table has a nullable datevalue field. When I try to update the value of the date field to DateTime.UtcNow the compiler complains that "This expression was expected to have type Nullable<DateTime> but here has type DateTime". How do I convert/cast from DateTime to Nullable<DateTime>.

My code currently looks something like follows:

for queryItem in queryResult do
    queryItem.CurrentDate <-  DateTime.UtcNow  // This gives compiler error as described above

Regards

like image 883
Quintus Marais Avatar asked Jun 24 '13 10:06

Quintus Marais


1 Answers

The comment by John Palmer above links to the solution. One needs to use the System.Nullable constructor i.e.

queryItem.CurrentDate <- System.Nullable DateTime.UtcNow
like image 119
Quintus Marais Avatar answered Sep 18 '22 14:09

Quintus Marais