How does one get a datetime column in a Dataframe to be just the time in the format of “HH:MM:SS”. Currently, those with a time entered, reads as 1899-12-30T13:00:00 and I need it to be just 13:00
The reason is that I will add this to the previous column which is the Date (example 2019-04-22T00:00:00) and then subtract off the InitalDate to get the Elapsed Days for each row in the DataFrame
For you math types it’s
ED=(df.PickDay+df.PickTime)-df.StartDate
ED is then stored in the dataframe for further use.
This seems to be quite simple but I appear to be missing something.
Thank you but here is the issue I am running into.
The data I would like to perform the operation on is in a DataFrame and when I try
Dates.format(df.PickTime,"H:M")
where df.Picktime is a DateTime datatype.
I get the error MethodError: no method matching format(::typeof(Dates.format), ::String) The function `format` exists, but no method is defined for this combination of argument types
I’m sure it is a something easy I am not thinking of but I cannot seem to get it work.
Dates.format expects a single DateTime as first argument. If you pass a Vector, you have to apply the function to each element, e.g. via broadcasting: Dates.format.(df.PickTime, "H:M")
Note the additional dot.
But this was not your initial problem. To add or subtract from DateTime variables you have to convert them to Periods (see Dates · The Julia Language), e.g.
It seems you’re misusing DateTime, consider using just Dates.Time, or after you’ve figured this out make such a column from your DateTime. I was thinking/hoping it would also save you some space (but it does not, would with some alternative type…):
Time should be able to fit into UInt16 if you really want to, down to minute, and almost if down to seconds, but not quote, accuracy to every other would fit… log2(246060) = 16.4 bits.
Time in some databases might be only (2 or) 4 bytes, but I see it’s actually also 8 bytes also in PostgreSQL in (down to microsecond, even if you do not take advantage of it), Date is 8 bytes in Julia, unlike in PostgreSQL, where it’s 4 bytes:
Time is “3 to 5” bytes. Not sure if it applies to your Access database, likely though, Maybe I was wrong and smaller than 8 is possible with PostgreSQL, but it seemed not from my quick reading. You can use Access with any database including it, i.e. as a front-end.
Interesting. The data is coming in through a query to an Access database. I am not sure how to control the type in the query but I can convert the column to Time.