Change date format in MongoDB

MongoDBDatabaseBig Data Analytics

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
raja
Published on 13-May-2020 05:41:57
Advertisements