-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Query Optimization
It would be really nice to have a flexible date difference operator that calculates the difference between two dates resulting in a duration (e.g. duration in msecs, secs, mins, hours, etc).
Consider the following projection stage in an aggregation pipeline. I need to calculate the difference in days between two dates - and one date may be null.
{ $project: { DIM: { $floor: { $divide: [ {$subtract: [ {$ifNull: [ '$DDAT', new Date()]}, '$FDAT' ]}, 86400000 ] } } } }
This works - and it's fast - but it would be more pleasant if I could specify something like:
{ $project: { DIM: { $diff: [ {$ifNull: [ '$DDAT', new Date()]}, '$FDAT', 'd' ] } } }
ArangoDB offers a date difference function which is pretty nice,
DATE_DIFF(date1, date2, unit, asFloat): Calculate the difference between two dates in given time unit, optionally with decimal places. Returns a negative value if date1 is greater than / after date2.
unit can be either of the following to specify the time unit to return the difference in (case- insensitive):
y, year, years
m, month, months
w, week, weeks
d, day, days
h, hour, hours
i, minute, minutes
s, second, seconds
f, millisecond, milliseconds
- related to
-
SERVER-10651 Aggregation expressions to add/subtract Years/Quarters/Months
- Closed