Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Change date format in MongoDB
We have the following date −
01-10-2019
To change the date format, let us use custom variable and convert date to a string and change its format −
Following is the query to implement date to string −
> var inputDate="01-10-2019"; > var formatDate= inputDate.split(/-|\//); > var outputString= formatDate[2]+'-'+formatDate[0]+'-'+formatDate[1];
Displaying the variable value −
> print(outputString);
This will produce the following output −
2019-01-10
Advertisements
