# Date issues

**URL:** <https://www.ruby-forum.com/t/date-issues/190986>\
**Category:** Rails\
**Created:** [July 1, 2010, 11:40pm UTC](https://www.ruby-forum.com/t/date-issues/190986 "2010-07-01T23:40:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![melomane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/da6949/32.png) [@melomane](https://www.ruby-forum.com/u/melomane)\
**Post date:** [July 1, 2010, 11:40pm UTC](https://www.ruby-forum.com/t/date-issues/190986/1 "2010-07-01T23:40:17Z")

</div>

Hi everyone. I know that the subject I chose is general, but it is a  
mixture of problems.  
I searched a lot in the group, in AWD with Rails book and some forums  
and found a lot of threads but none of them solved my problem, many of  
them didn’t work at all.  
The web site manager is going to set a start date for auction for  
every goods, it is not necessarily the date that object is added to  
database, but the manager has to set this date when he creates the  
object in database. I want to have a simple date form field with year  
month and day (for example 2010-05-09) but I don’t know how to convert  
it to date, the suggestions in the group didn’t work ( i mean to\_time  
and to\_date and etc)  
Every auction is available for just one week. If i convert the string  
to date i can easily add one week to the date. During the week for  
every goods, clients can input their desired prices.But the new  
problems arise, how can I find today’s date is equal to the end date?  
does it need a daily schedule for one week? It seems schedules are  
complicated in Rails. Also when the maximum price for an object has  
been chosen, do i have to delete the prices of ended auctions in order  
to prevent the database getting bigger and bigger? or it is not  
important?  
Thanks a million and Excuse me for my long scenario.

---

<div class="post-metadata">

**Author:** ![melomane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/da6949/32.png) [@melomane](https://www.ruby-forum.com/u/melomane)\
**Post date:** [July 2, 2010, 3:02am UTC](https://www.ruby-forum.com/t/date-issues/190986/2 "2010-07-02T03:02:51Z")

</div>

On Thu, Jul 1, 2010 at 2:39 PM, melomane [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Every auction is available for just one week. If i convert the string  
> to date i can easily add one week to the date. During the week for  
> every goods, clients can input their desired prices.But the new  
> problems arise, how can I find today’s date is equal to the end date?

Equal, or just not there yet? 🙂

> > endtime = Date.new(2010,7,4)  
> > =\> Sun, 04 Jul 2010  
> > endtime.future?  
> > =\> true  
> > now = DateTime.now.to\_date  
> > =\> Thu, 01 Jul 2010  
> > now.future?  
> > =\> false

(see the doc for ActiveSupport::CoreExtensions:📅:Calculations)

> … do i have to delete the prices of ended auctions in order  
> to prevent the database getting bigger and bigger? or it is not  
> important?

How much is “bigger”? If you can afford the disk space, why worry?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![melomane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/da6949/32.png) [@melomane](https://www.ruby-forum.com/u/melomane)\
**Post date:** [July 2, 2010, 3:08pm UTC](https://www.ruby-forum.com/t/date-issues/190986/3 "2010-07-02T15:08:40Z")

</div>

On 1 July 2010 22:39, melomane [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> it to date, the suggestions in the group didn’t work ( i mean to\_time  
> and to\_date and etc)

Rather than storing a string I would suggest storing a datetime value  
and just ignoring the time part(or make sure it is always 00:00).  
Then it is immediately comparable with other dates by simple  
comparison.

If you really need to convert the string then separate out the year,  
month, day and use Time.utc, passing it the values, to create the time  
object.

Colin
