# Comparing times in a dataframe

**URL:** <https://discourse.julialang.org/t/comparing-times-in-a-dataframe/112131>\
**Category:** General Usage\
**Tags:** dataframes, datetime\
**Created:** [March 26, 2024, 10:33am UTC](https://discourse.julialang.org/t/comparing-times-in-a-dataframe/112131 "2024-03-26T10:33:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Sevaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc_sevaux/32/14986_2.png) [@Marc\_Sevaux](https://discourse.julialang.org/u/Marc_Sevaux)\
**Post date:** [March 26, 2024, 10:33am UTC](https://discourse.julialang.org/t/comparing-times-in-a-dataframe/112131/1 "2024-03-26T10:33:25Z")

</div>

Dear all,  
I am not very comfortable with time formats. I have the following dataframe.

```julia
┌─────────┬──────────┐
│ id_site │ hour │
│ String7 │ Time │
├─────────┼──────────┤
│ BAN4 │ 08:48:00 │
│ BAN4 │ 08:56:00 │
│ BAN4 │ 09:01:00 │
│ BAN4 │ 09:37:00 │
│ BAN4 │ 09:49:00 │
│ BAN4 │ 10:02:00 │
│ BAN4 │ 10:05:00 │
│ BAN4 │ 10:40:00 │
│ BAN4 │ 12:05:00 │
│ BAN5 │ 08:41:00 │
└─────────┴──────────┘

```

How can I filter the lines to keep only those for hour greater that 09:30 for example?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 26, 2024, 10:43am UTC](https://discourse.julialang.org/t/comparing-times-in-a-dataframe/112131/2 "2024-03-26T10:43:32Z")

</div>

```julia
df[df.hour .> Time(9, 30), :]

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 26, 2024, 11:31am UTC](https://discourse.julialang.org/t/comparing-times-in-a-dataframe/112131/3 "2024-03-26T11:31:22Z")

</div>

Btw for straightforward questions like that AI works pretty well. Here’s what I got from JuliaHub’s AI assistant:

> To filter the lines in your DataFrame to keep only those with an hour greater than 09:30, you can use the following code snippet in Julia:

```julia
using DataFrames

# Sample DataFrame
df = DataFrame(id_site = ["BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN4", "BAN5"],
               hour = [Time("08:48:00"), Time("08:56:00"), Time("09:01:00"), Time("09:37:00"), Time("09:49:00"),
                       Time("10:02:00"), Time("10:05:00"), Time("10:40:00"), Time("12:05:00"), Time("08:41:00")])

# Filter the DataFrame to keep only rows with hour greater than 09:30
filtered_df = filter(row -> row.hour > Time("09:30:00"), df)

```

FWIW using `filter` I would write this as:

```julia
filter(:hour => >(Time(9, 30)), df)

```
