What is the preferred format to store date/times in a SQL Server database when PHP is your primary language?

前端 未结 3 1669
野趣味
野趣味 2021-02-05 22:25

I am planning a PHP application that needs to store date/times in an MSSQL database. (For the curious, it is a calendar application.) What is the preferred format to store this

3条回答
  •  醉梦人生
    2021-02-05 23:11

    I'd recommend the same as i do for all dates in any db engine, the db native type. (DATETIME)

    Just use "YYYY-MM-DD HH:MM:SS" for inserting in php: date('Y-m-d H:i:s', $myTimeStampInSeconds);

    -edit in response to comments below here -

    1. for selected columns you can use $timestamp = strtotime( $yourColumnValue );
    2. i recommend storing in the databas native format because you can then use SQL to compare records using SQL date/time functions like DATEADD() etc.

提交回复
热议问题