What would be the correct way to save the Date value in a database with setting in-US?
Assuming that the field in the database is of type DateTime
or Date
, the date format that will not give you problems to represent a date as a string in an Insert / Update statement, with SQL Server installed and configured in different languages, it is YYYYMMDD for date only and YYYYMMDD HH: MM: SS for date / time. Yes, without hyphens and with two points; I know it's weird if you have background from another database, but that's SQL Server (and I'm not going to defend it).
With this in mind, you could modify your code to this:
propertyInfo.SetValue(inputObject, Convert.ToDateTime(propertyVal).ToString("yyyyMMdd"), null);
And in theory it should work
That said ...
Avoid using textual representations for dates, numbers, etc.
The data access interfaces of most modern languages have the ability to perform correctly the task of sending and retrieving information correctly to virtually any database engine, if you represent the data in native language formats . The authors of the drivers of the different engines have taken care of these little big details (that if the decimal point is a point, or a comma, that if the date is represented in one way or another ). In fact, many database clients will accept the binary data, which also optimizes the process time and travel through the network.
If you can, send the dates as dates, the numbers as numbers, etc. and forget about these problems forever.