# How to decompose a DatePeriod or TimePeriod in tuple of (Y,m,d,H,M,S,s)?

``````using Dates
longPeriod = Date(2024,6,1) - Date(2022,1,20)
``````

How can I decompose `longPeriod` (or a `TimePeriod`) in a tuple of (years,months,days,hours,minutes,seconds,milliseconds) ?

I know `canLongPeriod = Dates.canonicalize(longPeriod)` returns a CompoundPeriod object, but in terms of weeks and further, I don’t then know how to handle it.

But I guess the problem is complicated from the fact that 1 year or 1 month is not always the same number of days, so maybe my question doesn’t make much sense…

Does a `Period` store information also on when it starts? If not, does a “TimedPeriod” with starts + length exists?

FWIW, by calling Python from Julia we can obtain the number of years, months, days, etc., elapsed between two dates:

``````using PyCall
datetime = pyimport("datetime")
dateutil = pyimport("dateutil")
relativedelta = pyimport("dateutil.relativedelta")
d1 = datetime.datetime(2022,1,20)
d2 = datetime.datetime(2024,6,1)
dt = dateutil.relativedelta.relativedelta(d2, d1)

# results:
dt.years, dt.months, dt.days, dt.hours, dt.minutes, dt.seconds, dt.microseconds
(2, 4, 12, 0, 0, 0, 0)
``````
``````julia> time2 = DateTime(2024,6,1)
2024-06-01T00:00:00

julia> time1 = DateTime(2022,1,20)
2022-01-20T00:00:00

julia> x = Dates.periods(Dates.canonicalize.(Dates.CompoundPeriod.(time2 - time1)))
2-element Vector{Period}:
123 weeks
2 days

``````

It’s not exactly what you were looking for but it’s entirely in Julia. It appears that it the largest unit it returns is weeks. I don’t know exactly why but my instant theory is that months and years aren’t fixed sizes absolutely.

@Daneel, according to OP: