Integer to Julia Date Value

823 views
Skip to first unread message

Min-Woong Sohn

unread,
Dec 19, 2014, 10:09:42 PM12/19/14
to julia...@googlegroups.com


Date("1960/1/1","yyyy/m/d") returns 1960-01-01, whose integer value is 715510. I want to convert this integer back to Date type. How do I do that? 

Also I noticed that Date(1) returns 0001-01-01 and Date(2) returns 0002-01-01 and Date(715510) returns 715510-01-01. Isn't this more natural that Date(2) returns 0001-01-02 and Date(715510) returns 1960-01-01? Just my opinion.

Avik Sengupta

unread,
Dec 20, 2014, 11:05:26 AM12/20/14
to julia...@googlegroups.com

julia> d2=Date(Dates.UTD(715510))
1960-01-01

Min-Woong Sohn

unread,
Dec 20, 2014, 4:24:39 PM12/20/14
to julia...@googlegroups.com
Thank you so much!

Jacob Quinn

unread,
Dec 20, 2014, 11:57:23 PM12/20/14
to julia...@googlegroups.com
Yeah, I'd be open to changing the behavior of one-arg `Date()` if there was enough support. The reason for the current behavior is to provide consistency, i.e.:

Date(y) -> Date(y,1,1)
Date(y,m) -> Date(y,m,1)

Similarly with DateTime:

DateTime(y,m,d) -> DateTime(y,m,d,0,0,0,0)
etc.

I guess we should at least have a better API for creating a Date/DateTime from the `Dates.value(dt::Date)` integer value. 

-Jacob

Avik Sengupta

unread,
Dec 21, 2014, 8:03:00 AM12/21/14
to julia...@googlegroups.com, quinn....@gmail.com
I'm not sure if I like the idea of privileging a Date constructor for the Rata integer, even if that is the internal representation. I'd rather have consistent conversion functions for different representations, since I can think of many other ways to convert an integer or a float to a Date. For example,  I often need to convert an Excel date (days from 1900 or 1904, in fractions). Or unix epochs. Or Julian day numbers.

Regards
-
Avik

Tomas Lycken

unread,
Dec 21, 2014, 9:36:48 AM12/21/14
to julia...@googlegroups.com, quinn....@gmail.com

Aren’t unix2datetime et al a good enough interface? The documented ones only give DateTimes, not Dates, but I guess it would be fairly easy to add sister methods that do that (simply by wrapping the constructor, e.g. unix2date(x) = Date(unix2datetime(x))).

// T

Reply all
Reply to author
Forward
0 new messages