[SERVER-4434] aggregation: add strptime functionality to parse string dates into ISODates Created: 06/Dec/11 Updated: 06/Dec/22 Resolved: 16/Mar/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Daniel Pasette (Inactive) | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Duplicate | Votes: | 13 |
| Labels: | expression | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Assigned Teams: |
Query
|
||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||
| Description |
|
Example: |
| Comments |
| Comment by David Storch [ 16/Mar/18 ] | ||||||||||||||||||||||||||||||||||||||
|
Marking as a duplicate of | ||||||||||||||||||||||||||||||||||||||
| Comment by Asya Kamsky [ 15/Mar/18 ] | ||||||||||||||||||||||||||||||||||||||
|
Now that $dateFromString takes an optional "format" argument, you can specify custom format for parsing any string into a date. Example:
In addition, you can optionally specify "onError" and "onNull" parameters which provide the value to use if null (or empty) input is provided, and if an error is encountered when attempting to convert the string to date. Example syntax would be:
| ||||||||||||||||||||||||||||||||||||||
| Comment by Asya Kamsky [ 14/Mar/18 ] | ||||||||||||||||||||||||||||||||||||||
|
Now that $dateFromString takes a format string, I believe this can be closed. See | ||||||||||||||||||||||||||||||||||||||
| Comment by David Storch [ 04/Oct/17 ] | ||||||||||||||||||||||||||||||||||||||
|
An update on this ticket: We have implemented a new aggregation framework operator called $dateFromString under
We can also parse ISO 8601 variations such as those that omit the time of day, or which omit dashes or colons:
Lastly, we can handle ISO 8601 week-numbered dates using formats like YYYY-Www-DThh:mm:ss.sssZ:
I can't currently claim full ISO 8601 compliance, but I believe that we can correctly handle any valid ISO 8601 date string in the years 0000-9999. I'm leaving this ticket open to track the remaining strptime()-like functionality in which the user can specify the expected format of the date via a format string. This would allow applications to use the aggregation framework to easily parse non-standard date formats to UTC datetimes (milliseconds since the Unix epoch). | ||||||||||||||||||||||||||||||||||||||
| Comment by Gabriel Zimmermann [ 21/Feb/17 ] | ||||||||||||||||||||||||||||||||||||||
|
Any ETA on this? I need this feature for my aggregation pipeline. I can group by date, but I need to calculate the offset of a document until the end of the `$group` and this is the only way I can think of. | ||||||||||||||||||||||||||||||||||||||
| Comment by Andy Schwerin [ 02/May/16 ] | ||||||||||||||||||||||||||||||||||||||
|
The example from the description:
suggests that the parser will presume that "no timezone provided" equals "UTC timezone". I suggest instead that we should issue an error if the user fails to provide a timezone. | ||||||||||||||||||||||||||||||||||||||
| Comment by Eliot Horowitz (Inactive) [ 20/Apr/12 ] | ||||||||||||||||||||||||||||||||||||||
|
The latter, a new function called $stptime | ||||||||||||||||||||||||||||||||||||||
| Comment by Annie Chin [ 20/Apr/12 ] | ||||||||||||||||||||||||||||||||||||||
|
I wanted to try implementing this ticket, |