I tried the below, it was able to generate the number I want, i.e., 730824, but how can I extract this number out?
A = dump(Date(2001, 12, 5))
value: Int64 730824
julia> Date(2001, 12, 5).instant.periods.value
julia> using Dates
julia> a = Date(2001,12,5)
Both methods work! Many thanks, All.
Note that this method will not work for all datetimes:
julia> using Dates
julia> d = now()
value: Int64 63770884754665
The question is - to what resolution do you want this value? Relative to what,
01-01-1970? How do you get them and what do you want to do with them?
Thanks. I only need to have some loose idea, so precision to the day is more than enough. I have several decades of sampling data and I just want to see the date in the middle.
BTW, once I get the average datenumber, how do I convert it back to Date? I tried the below and it did not work well.
A = Date(2001,12,5);
B = Dates.value(A); # get the date number
C = Dates.Date(B); # Trying to convert the date number back to date.
I think you’re looking for
datetime2unix (which takes a
DateTime). Julia has proper datetime arithmetic built in, so you should not have to work with the raw values.
Maybe you can explain what you want to do with them?
I have several decades of sampling data. They have date information stored as 3 separate columns:
Day. What I need to find out is the average date.
Are you talking about the median, geometric or arithmetic mean…? How do you want to round, in case you don’t get an even integer (truncation, towards/away from zero, towards positive/negative infinity, …)?
Sorry if I come across as intrusive, it’s just hard for me to give a concrete suggestion when I’m not clear what you’re talking about
No at all. I really appreciate your help.
My variables are changing smoothly with time. I want to find out the average date value so that I can adjust all data to that date. I think what I need is the arithmetic mean? I can round the results, so that shouldn’t be a problem. For this post, I just want to find out how to convert a date number like 730824 back to a date or its original Year, Monty and Day. Thanks.
You can use the
using Dates, Random
d = rand(Date(2021,10,1):Day(1):today(), 10)
d̄ = Date(Dates.UTD(round(Int, mean(Dates.value.(d)))))
It works like a charm! Thank you so much