I am manipulating a text file, I need to extract dates from it, that will be in the format



_ is either 1 or zero whitespaces __ is 1 or more than 1 whitespaces X is a combination of 0 or more whitespaces and 0 or 1 newlines

I need to get the date and calculate the time difference (in days) from now to those dates. I would need a function timedifference[string_] that does that, but I don't know how to build it, (or better, I think I could do it in a very mechanical way, I hoped some expert could show me an easy and short solution)


This should work for all of the specified combinations of whitespace/newline

date = "   Jan  28 ,  2020 \n"
dateObj = date // StringReplace[" " -> ""] // DateObject[{#, {"Month", "Day", "Year"}}] &
DateDifference[dateObj, Today]

(* Quantity[21, "Days"] *)

Your Answer

