DateTime issue when global culture of the server is different on different servers

后端 未结 4 1155
闹比i
闹比i 2020-12-10 16:15

My website is hosted on multiple servers at different locations

Everywhere the Culture of the data format is different- we use mm/dd/yyyy format every w

4条回答
  •  佛祖请我去吃肉
    2020-12-10 17:15

    Never, ever, store dates internally as strings. Not in the database, not in your app.

    If you need to move date values between servers, go binary. Or if you really really have to use strings, use ToString(CultureInfo.InvariantCulture) - or simply serialize the Ticks property.

    Also, never pass dates as strings to the database using SQL commands that you build using code. Use SqlParameter for that, or even better, rely on some O/R Mapper, such as Entity Framework or Linq to SQL.

提交回复
热议问题