# Basic date/time question

**URL:** <https://www.ruby-forum.com/t/basic-date-time-question/123711>\
**Category:** Ruby\
**Created:** [December 19, 2007, 10:28pm UTC](https://www.ruby-forum.com/t/basic-date-time-question/123711 "2007-12-19T22:28:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvertab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@silvertab](https://www.ruby-forum.com/u/silvertab)\
**Post date:** [December 19, 2007, 10:28pm UTC](https://www.ruby-forum.com/t/basic-date-time-question/123711/1 "2007-12-19T22:28:20Z")

</div>

I’m trying to calculate a period of time; basically each month is  
divided in 2 periods, from the 1st of the month to the 15th is period1,  
and from the 16th to the last day of the month is period2…

Now my problem is that…I’m not sure if midnight (00:00:00) is  
considered the "end " of the current day, or the “start” of the next  
day…

So for example; is December 15th, midnight (00:00:00) considered the  
very start of December 15th, or the very end of it?

Basically, I’m not sure as to where a “day” starts and ends?  
(ex: from 00:00:00 to 11:59:59? or from 00:00:01 to 00:00:00 etc…)

Any help would be appreciated… I know it might sound a bit confusing, I  
can try to explain it better…

---

<div class="post-metadata">

**Author:** ![silvertab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@silvertab](https://www.ruby-forum.com/u/silvertab)\
**Post date:** [December 19, 2007, 10:35pm UTC](https://www.ruby-forum.com/t/basic-date-time-question/123711/2 "2007-12-19T22:35:39Z")

</div>

On Dec 19, 2007, at 4:28 PM, Jean-nicolas Jolivet wrote:

> very start of December 15th, or the very end of it?
> 
> Basically, I’m not sure as to where a “day” starts and ends?  
> (ex: from 00:00:00 to 11:59:59? or from 00:00:01 to 00:00:00 etc…)
> 
> ## Any help would be appreciated… I know it might sound a bit confusing, I can try to explain it better…

Midnight is the START of the day.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![silvertab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@silvertab](https://www.ruby-forum.com/u/silvertab)\
**Post date:** [December 19, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/basic-date-time-question/123711/3 "2007-12-19T22:39:43Z")

</div>

Gotcha, so basically, using December as an example, the period1 would  
be:  
From: December 1, 00:00:00 (midnight)  
To: December 15, 11:59:59

and Period2:  
From: December 16th 00:00:00 (midnight)  
To: December 31st 11:59:59

right? Just want to make sure I’m not “missing a second”…

Rob B. wrote:

> On Dec 19, 2007, at 4:28 PM, Jean-nicolas Jolivet wrote:
> 
> Midnight is the START of the day.
> 
> -Rob
> 
> Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![silvertab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@silvertab](https://www.ruby-forum.com/u/silvertab)\
**Post date:** [December 20, 2007, 12:10am UTC](https://www.ruby-forum.com/t/basic-date-time-question/123711/4 "2007-12-20T00:10:54Z")

</div>

Rob B. wrote:

> Or (after converting the strings to real Time objects):
> 
> period1 = (“December 1, 00:00:00”…“December 16, 00:00:00”)
> 
> period2 = (“December 16, 00:00:00”…“January 1, 00:00:00”)
> 
> Note the end-excluding three-dot Range constructor.
> 
> This way of thinking works with Date or Time and means that for any  
> given date in December, only one of these can be true:
> 
> period1.include?(given)  
> period2.include?(given)
> 
> -Rob

Great… makes more sense that way! Thank you 🙂

---

<div class="post-metadata">

**Author:** ![silvertab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@silvertab](https://www.ruby-forum.com/u/silvertab)\
**Post date:** [December 19, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/basic-date-time-question/123711/5 "2007-12-19T23:27:31Z")

</div>

Or (after converting the strings to real Time objects):

period1 = (“December 1, 00:00:00”…“December 16, 00:00:00”)

period2 = (“December 16, 00:00:00”…“January 1, 00:00:00”)

Note the end-excluding three-dot Range constructor.

This way of thinking works with Date or Time and means that for any  
given date in December, only one of these can be true:

period1.include?(given)  
period2.include?(given)

-Rob
