How to convert JS date time to MySQL datetime?

MySQLMySQLi Database

We can convert JS date time to MySQL datetime with the help of toISOString() function.

Let us see an example of JavaScript.

Example

 Live Demo

<!DOCTYPE html>
<html>
   <head>
      <title>Web Page Design</title>
      <script>
         document.writeln(new Date().toISOString().slice(0, 19).replace('T', ' '));
      </script>
   </head>
<body>
   <br>Current Date is displayed above...
</body>
</html>

Output

The following is the output.

2018-11-23 11:14:38
Current Date is displayed above...
raja
Published on 23-Nov-2018 12:14:11
Advertisements