qb icon indicating copy to clipboard operation
qb copied to clipboard

SQL Server: Inserting Empty String in DateTime Column Becomes 1/1/1900

Open homestar9 opened this issue 10 months ago • 2 comments

Imagine you want to save a struct like this to the database:

myFruit = {
	"name": "Banana",
	"color": "Yellow",
	"eatenDate": ""
};

qb.from( "fruit" ).insert( myFruit );

One would think that when you query the fruit you just inserted, the eatenDate value would be null. However, in MSSQL server if you insert an empty string (''), it will set the date to 1/1/1900.

Now, you could fix this by explicitly setting myFruit.eatenDate to { value="", null=true }. However, this extra step should be optional since most developers would expect QB to interpret an empty string as null when persisting the data to the database.

homestar9 avatar Apr 08 '24 21:04 homestar9