Best way to store date and time using MySQL PHP + AJAX

I am creating a web-based project management application using MySQL and PHP, which uses JS (jQuery) in the interface. The user must enter a date and, if necessary, time.

However, I am not sure how I should insert and store the date and convert it back to a human form in the application.

Thanks in advance RayQuang

+4
source share
2 answers

Always use standard Date / Time types for your situation.

In MySQL, use one of the appropriate Date and Time Type . Do not just blindly use one type. If you are storing a date, do not use a timestamp. If you keep the timestamp, do not use the date. Use the correct type and do it.

In PHP you can use an integer (sort out the mysql type with strtotime() .

Speaking to JS, I would suggest using the RFC 2822 date format as it is standard. This way you are interfacing using a standard date / time format (which is not ambiguous).

+7
source

Save as timestamp.timestamp, contains both date and time. and this will be the best way to store the date and time.

+1
source

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


All Articles