Rozaimi Rozaimi - 1 month ago 11
MySQL Question

Date, Time, TimpStamp format in PHP mysqli

if date format in PHP mysqli can be declare as below :

$date = $_POST['date'];
$statement = mysqli_prepare($connect, "INSERT INTO table (date) VALUES (?)");
$addDate = date("Y-m-d", strtotime($date));
mysqli_stmt_bind_param($statement, "s", $addDate);


How to add Datetime, Time , TimeStamp format ?

thanks.

Answer

MySQL DateTime/Timestamp Format for PHP output

Y-m-d H:i:s

MySQL Date

Y-m-d

MySQL Time

 H:i:s

Reference

The DATE, DATETIME, and TIMESTAMP types are related. This section describes their characteristics, how they are similar, and how they differ. MySQL recognizes DATE, DATETIME, and TIMESTAMP values in several formats, described in Section 10.1.3, “Date and Time Literals”. For the DATE and DATETIME range descriptions, “supported” means that although earlier values might work, there is no guarantee.

The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

And for TIME

MySQL retrieves and displays TIME values in 'HH:MM:SS' format (or 'HHH:MM:SS' format for large hours values). TIME values may range from '-838:59:59' to '838:59:59'. The hours part may be so large because the TIME type can be used not only to represent a time of day (which must be less than 24 hours), but also elapsed time or a time interval between two events (which may be much greater than 24 hours, or even negative).

(emphasis mine)

Comments