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

后端 未结 4 1149
闹比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 16:53

    Never rely on the server's default locale. For your case, this means:

    • Use prepared statements where you pass the date as (unformatted) date object and not as (formatted) string object. You should never use strings to represent dates in your application anyway, as you cannot perform date-specific functions on them (like adding 1 month, getting the last day of the current week, etc.)

    • Use SQL functions like to_date and to_char everywhere (exact names depend on your DBMS), if you really need to use string objects in your application

提交回复
热议问题