Question: I need to parse date value to specific format without using format field in dateFromString operator. 

[Mongo Playground](https://mongoplayground.net/p/U9thsJCE88V)

Current situation : 
in Mongodb 4.0 if I format dateString using below it code it give me mentioned output. 

```
 parsedDate: {
        $dateFromString: {
          dateString: "$dateS",
          format: format: "%Y-%m-%dT%H"
        }
      }
Output: "parsedDate": ISODate("2020-01-16T08:00:00Z")

```

I cannot use format field in 3.6 since its not supported.
How do I convert my date to
 `format: "%Y-%m-%dT%H"` in 3.6?

Answer: 
If I get the requirement right, Try the following query which uses: [`$dateFromParts`](https://docs.mongodb.com/manual/reference/operator/aggregation/dateFromParts/)

**Input:**

```
[
  {
    "date": ISODate("2020-01-16T08:54:17.604Z")
  }
]

```

**Query:**

```
db.collection.aggregate([
  {
    $project: {
      outputDate: {
        $dateFromParts: {
          "year": {
            $year: "$date"
          },
          "month": {
            $month: "$date"
          },
          "day": {
            $dayOfMonth: "$date"
          },
          "hour": {
            $hour: "$date"
          }
        }
      }
    }
  }
]);

```

**O/P:**

```
[
  {
    "_id": ObjectId("5a934e000102030405000000"),
    "outputDate": ISODate("2020-01-16T08:00:00Z")
  }
]

```

[Playground Test Link](https://mongoplayground.net/p/BiAeIbEBZCO)
This worked for me: I used combined solution from @ambienBeing and @techstack. Thanks 

[Mongo playground](https://mongoplayground.net/p/aUBwxfZO_Qm)

```
  "parsedDate": {
          "$dateFromParts": {
            "year": {
              "$year": {
                $dateFromString: {
                  dateString: {
                    "$concat": [
                      "$_id.dateHour",
                      ":00:00Z"
                    ]
                  }
                }
              }
            },
            "month": {
              "$month": {
                $dateFromString: {
                  dateString: {
                    "$concat": [
                      "$_id.dateHour",
                      ":00:00Z"
                    ]
                  }
                }
              }
            },
            "day": {
              "$dayOfMonth": {
                $dateFromString: {
                  dateString: {
                    "$concat": [
                      "$_id.dateHour",
                      ":00:00Z"
                    ]
                  }
                }
              }
            },
            "hour": {
              "$hour": {
                $dateFromString: {
                  dateString: {
                    "$concat": [
                      "$_id.dateHour",
                      ":00:00Z"
                    ]
                  }
                }
              }
            }
          }
        },

```