# Tuple to DateTime

**URL:** <https://discourse.julialang.org/t/tuple-to-datetime/114066>\
**Category:** General Usage\
**Tags:** question, tuple, datetime\
**Created:** [May 9, 2024, 8:17pm UTC](https://discourse.julialang.org/t/tuple-to-datetime/114066 "2024-05-09T20:17:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DTL](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@DTL](https://discourse.julialang.org/u/DTL)\
**Post date:** [May 9, 2024, 8:17pm UTC](https://discourse.julialang.org/t/tuple-to-datetime/114066/1 "2024-05-09T20:17:18Z")

</div>

I’m processing a CSV file where I have a couple of years of recordings, there are several readings per hour, and I’m summing them altogether to get a total per day.

I get the data into a dataframe ok.

`julia> df`  
`32047×6 DataFrame`  
`Row │ Location date A mW/cm2 T degC RH %`  
` │ String15 DateTime Float64? Int64? Float64? Int64?`  
` 1 │ Mezzaine NE 2022-08-08T11:45:00 229.8 0 25.3 47`

I can get the vales of A for each day and sum these with

`gdf = groupby(transform(df, :date => x->yearmonthday.(x)),:date_function)`  
`A_totals = combine(gdf,:A => sum)`

The problem is this put the date as a tuple into the new dataframe  
`julia> A_totals`  
'349×2 DataFrame` `(2022, 8, 8) 2921.49` `(2022, 8, 9) 5954.86`

I need to have that tuple as a DateTime type, I tried converting it by cturning it into a string, or using a DateFormat specifier, but neither worked.

`julia> d`  
`(2022, 8, 8)`

`julia> ds=string(d)`  
`"(2022, 8, 8)"`  
`dt=DateTime(ds)`  
`ERROR: ArgumentError: Invalid DateTime string`

`julia> df`  
`dateformat"(Y, M, D)"`  
`julia> Date(d,df)`  
`ERROR: MethodError: no method matching Int64(::Tuple{Int64, Int64, Int64})`

Now I’m stuck.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [May 9, 2024, 8:29pm UTC](https://discourse.julialang.org/t/tuple-to-datetime/114066/2 "2024-05-09T20:29:39Z")

</div>

```julia

julia> Date(2022, 8, 8)
2022-08-08

julia> d=(2022, 8, 8) #If you have the triple of values ​​in a tuple, 
(2022, 8, 8)

# don't do this.

julia> Date(d)
ERROR: MethodError: no method matching Int64(::Tuple{Int64, Int64, Int64})
# instead do this
julia> Date(d...)

```

---

<div class="post-metadata">

**Author:** ![DTL](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@DTL](https://discourse.julialang.org/u/DTL)\
**Post date:** [May 9, 2024, 8:38pm UTC](https://discourse.julialang.org/t/tuple-to-datetime/114066/3 "2024-05-09T20:38:36Z")

</div>

Thank you! That seems to work, but why does that work?  
What does … mean in this context?

---

<div class="post-metadata">

**Author:** ![anonymous\_shrew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anonymous_shrew/32/210646_2.png) [@anonymous\_shrew](https://discourse.julialang.org/u/anonymous_shrew)\
**Post date:** [May 9, 2024, 9:14pm UTC](https://discourse.julialang.org/t/tuple-to-datetime/114066/4 "2024-05-09T21:14:46Z")

</div>

> [@DTL](#):
>
> What does … mean in this context?

It is the [splatting operator](https://docs.julialang.org/en/v1/manual/faq/#The-two-uses-of-the-...-operator:-slurping-and-splatting).

---

<div class="post-metadata">

**Author:** ![DTL](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@DTL](https://discourse.julialang.org/u/DTL)\
**Post date:** [May 10, 2024, 6:27am UTC](https://discourse.julialang.org/t/tuple-to-datetime/114066/5 "2024-05-10T06:27:50Z")

</div>

Thank you.
