As you have seen in other examples in this chapter and earlier chapters, it is always possible to work with date strings. The problem with this approach, however, is that the data you have to work with might not be clean in that different date formats may have been used. This is especially true in situations where the data has accumulated over a period of time, perhaps from different versions of the web application.
Another problem when trying to perform operations on dates as strings is that performing date arithmetic becomes problematic. You will learn more about this later in this chapter when it comes time to present a solution for generating a 30-60-90 day aging report, which is a typical requirement for accounting purposes.
For the purposes of this sub-section, we will examine the more important date expression operators. There are two operators that create BSON date objects:
- $dateFromParts: Creates a BSON date object from parameters that include the year...