0

I have a nested list that contains date strings that I've split on the forward slash in the form of year/month/day/hour/minute, like so:

list = {{2016, 3, 3, 4, 25}, {2016, 3, 5, 3, 32}, {2016, 3, 8, 11, 54} .....}

I want to find the DateDifference between every one of these dates and {2016, 1, 1, 0, 0} (aka Jan 1st, 2016). I've tried using Map as well as attempted to pass the entire list as the second argument of DateDifference, but neither has worked; using Map only works if I don't provide any arguments to DateDifference,

DateDifference/@list

which will try to take the DateDifference between elements (not what I want), and I guess DateDifference is not listable. Is there a simple way to do this? I would prefer not to use DateObjects as they are very slow.

Lame-Ov2.0
  • 353
  • 1
  • 10
  • Table[QuantityMagnitude[DateDifference[{2016, 1, 1, 0, 0}, d]], {d, {{2016, 3, 3, 4, 25}, {2016, 3, 5, 3, 32}, {2016, 3, 8, 11, 54}}}]? (Remove QuantityMagnitude[] if you want to keep the units.) – J. M.'s missing motivation Aug 09 '16 at 17:32
  • @J.M. It is not practical for me to explicitly write every sublist that I want the difference taken from, as my list is quite large. If Table is listable though, it might work – Lame-Ov2.0 Aug 09 '16 at 17:37
  • 1
    What am I missing here? DateDifference[{2016, 1, 1, 0, 0}, #] & /@ {{2016, 3, 3, 4, 25}, {2016, 3, 5, 3, 32}, {2016, 3, 8, 11, 54}} works as expected – Jason B. Aug 09 '16 at 17:48
  • 1
    You're supposed to replace the list of dates; e.g. Table[QuantityMagnitude[DateDifference[{2016, 1, 1, 0, 0}, d]], {d, myLongListOfDates}] (and of course Jason's proposal is the alternative way to proceed). – J. M.'s missing motivation Aug 09 '16 at 18:00
  • @J.M. This is confusing for me: this piece of code is part of a larger set of pure function + postfix chaining I am doing on a set of imported data; what is d supposed to refer to, and how is d different from what I would input as myLongListOfDates? This list will be fed into the next input as a pure function slot. I'll edit my OP to try and be a bit more clear – Lame-Ov2.0 Aug 09 '16 at 19:50
  • d in the Table[] code is an index, in much the same way Table[d!, {d, 1, 5}] has d as an index. Are you familiar with the foreach construction in other languages? The equivalent in Jason's proposal is QuantityMagnitude[DateDifference[{2016, 1, 1, 0, 0}, #]] & /@ myLongListOfDates. – J. M.'s missing motivation Aug 09 '16 at 19:52
  • @J.M. That makes sense, I am familiar with Python's for. Thank you for clarifying. – Lame-Ov2.0 Aug 09 '16 at 20:05

0 Answers0