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

 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...
Updated on: 2020-06-27T07:14:32+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements