What is the best way to store date and time in MySQL?

I would like to save the date and time in the following format in the database

a) DD-MM-YYYY or I could add HH-MM b) since my servers are located in the USA, I would like to get the time according to IST. now it will be GMT: +5: 30

I used to store the date in mysql in this format timestamp (int (11)): 1291746600. I used to convert the date with strtotime (); currently my intention is to store the date - it's just to store and display. in the future I would like to calculate no. days, months, etc.

What would be the best solution for this?

P: S: I would appreciate it if someone could explain to me what data type to use and how to use it with PHP.

+3
source share
3

DATETIME fields! mySQL. , mySQL date.

, , DATETIME, DATE_FORMAT().

MySQL DATETIME - .

:

+10

datetime.

http://dev.mysql.com/doc/refman/5.1/en/datetime.html

.

varchar, ISO-TIME (YYYY-MM-DD), .

+3

I think you should use a data type DATETIME. For additional date and time operations, see the functions listed here. http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

+3
source

Source: https://habr.com/ru/post/1782772/


All Articles