2022-07-04

MongoDB - Remove the timestamp from a mongo date

 db.collection_name.aggregate([    

    {$addFields: {

        "date_with_uniform_time": {$dateTrunc: {

              date: "$source_date_field",

              unit: "day",

              timezone: "America/New_York",

           }},

    }},

    {$addFields: {

        "date_without_time": {$substr: [

            "$date_with_uniform_time", 

            0, 10

        ]}

    }},

]);