- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert MySQL DATETIME value to JSON format in JavaScript?
To convert, use JSON.stringify(). Following is the code to convert MySQL DATETIME value to JSON format in JavaScript −
<script> var mySQLDateTime = new Date("Fri Sep 06 2019 22 −54 −48 "); var yearValue = mySQLDateTime.getFullYear(); var dateValue = mySQLDateTime.getDate(); var monthValue=mySQLDateTime.getMonth(); var hour=mySQLDateTime.getHours(); var minutes=mySQLDateTime.getMinutes(); var second=mySQLDateTime.getSeconds(); jsonObject={"year" −yearValue,"month" :monthValue,"DateValue" :dateValue,"Hour" :hour ,"Minutes" :minutes,"Second" :second}; var dateJsonObject = JSON.stringify(jsonObject); document.write(dateJsonObject); </script>
The screenshot of the code is as follows −
This will produce the following output −
{"year" :2019,"month" :8,"DateValue" :6,"Hour" :22,"Minutes" :54,"Second" :48}
The snapshot of the output is as follows −
- Related Articles
- How to convert string to 24-hour datetime format in MySQL?
- Convert JSON to another JSON format with recursion JavaScript
- How to convert C# DateTime to “YYYYMMDDHHMMSS” format?
- How to use MySQL FROM_UNIXTIME() function to return datetime value in numeric format?
- Adding a day to a DATETIME format value in MySQL?
- How to convert Python date in JSON format?
- How to format JSON string in JavaScript?
- How to convert timestamp to datetime in MySQL?
- Add10 minutes to MySQL datetime format?
- Convert DateTime Value into String in MySQL?
- How to convert JSON object to Hashtable format using PowerShell?
- How to convert JSON text to JavaScript JSON object?
- How to convert DateTime to a number in MySQL?
- How to convert MySQL datetime to Unix timestamp?
- Convert INT to DATETIME in MySQL?

Advertisements