# \[Noob question\] Get an hour of a date

**URL:** <https://discourse.elm-lang.org/t/noob-question-get-an-hour-of-a-date/7064>\
**Category:** Learn\
**Created:** [March 8, 2021, 6:34pm UTC](https://discourse.elm-lang.org/t/noob-question-get-an-hour-of-a-date/7064 "2021-03-08T18:34:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nullpo](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/nullpo/32/3908_2.png) [@Nullpo](https://discourse.elm-lang.org/u/Nullpo)\
**Post date:** [March 8, 2021, 6:34pm UTC](https://discourse.elm-lang.org/t/noob-question-get-an-hour-of-a-date/7064/1 "2021-03-08T18:34:35Z")

</div>

Hi all!

I want to know how I can get the start of a day/a particular hour.

i.e.: I need to filter a list with all the elements that the attribute ‘date’ is after 11:00 am, local timezone (we can assume timezone = GMT+00:00).

I couldn’t find the way to make this… I prefer to do it without any other library than elm/time (for learning purposes), but if is complicated I can add a package.

I don’t have any problem getting the current date. So, I need to know how to make a function that, given a Posix time, I can get the 11:00 am date for that exactly day (also in posix).

Thank you folks!

---

<div class="post-metadata">

**Author:** ![aklaing](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@aklaing](https://discourse.elm-lang.org/u/aklaing)\
**Post date:** [March 8, 2021, 8:15pm UTC](https://discourse.elm-lang.org/t/noob-question-get-an-hour-of-a-date/7064/2 "2021-03-08T20:15:52Z")

</div>

If you decide to try other packages, you could consider this:

```
        waratuman/time-extra

```

and use the function `Time.Extra.startOfDay`

after that you can add 11 hours \* 60 minutes \* 60 seconds to that. This will not work on days where the daylight savings time changes.

---

<div class="post-metadata">

**Author:** ![DullBananas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/dullbananas/32/3709_2.png) [@DullBananas](https://discourse.elm-lang.org/u/DullBananas)\
**Post date:** [March 8, 2021, 9:37pm UTC](https://discourse.elm-lang.org/t/noob-question-get-an-hour-of-a-date/7064/3 "2021-03-08T21:37:32Z")

</div>

i think you will need to use functions such as `toMinute`. the documentation of some of these functions suck, so here’s an example

[https://ellie-app.com/czdR5rcfLK6a1](https://ellie-app.com/czdR5rcfLK6a1)

---

<div class="post-metadata">

**Author:** ![wolfadex](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/wolfadex/32/2461_2.png) [@wolfadex](https://discourse.elm-lang.org/u/wolfadex)\
**Post date:** [March 8, 2021, 11:16pm UTC](https://discourse.elm-lang.org/t/noob-question-get-an-hour-of-a-date/7064/4 "2021-03-08T23:16:47Z")

</div>

I’d highly recommend using [justinmimbs/time-extra](https://package.elm-lang.org/packages/justinmimbs/time-extra/latest/), if you go with a package, as it will cover almost everything you need.

If you decide to stick with just `elm/time` then I’d recommend looking at how that package does [floor](https://github.com/justinmimbs/time-extra/blob/42a54bc75535139980eb5a4d459e58c0e40989c3/src/Time/Extra.elm#L379) as this function takes a time zone, a posix value, and an interval (Day, Hour, etc) and gives your the start of it. There’s a lot of other goodies in the source code too around building up specific date-times.

---

<div class="post-metadata">

**Author:** ![Nullpo](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/nullpo/32/3908_2.png) [@Nullpo](https://discourse.elm-lang.org/u/Nullpo)\
**Post date:** [March 9, 2021, 7:51pm UTC](https://discourse.elm-lang.org/t/noob-question-get-an-hour-of-a-date/7064/5 "2021-03-09T19:51:14Z")

</div>

Thank you to all. At the end I used the answer provided by @wolfadex and @aklaing, with waratuman/time-extra package 😄

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [March 19, 2021, 7:52pm UTC](https://discourse.elm-lang.org/t/noob-question-get-an-hour-of-a-date/7064/6 "2021-03-19T19:52:13Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
