Computer >> Computer tutorials >  >> Programming >> MySQL

How to convert JS date time to MySQL datetime?


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

Let us see an example of JavaScript.

Example

<!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...