I want to know if there’s a way to change the date format depending on the users local date format setting. The date I will store in the DB it’s YYYY-MM-DD but the users have different formats, like DD-MM-YYYY or DD.MM.YYYY. What is a clean, elegant way to ensure that my application always retrives the date in local date format, and SQL server always receives the date in YYYY-MM-DD to be stored.
I want to know if there’s a way to change the date format depending
Share
No. If you do it right the storage in the Db does not have a format. It is stored, for example, as a number.
Your application receives it as a binary value too. You have to think about format every time it becomes a string.
For that you could rely on the machine configuration:
datevalue.ToString().But usually you want to take control:
datevalue.ToString(specificCultureInfo)