# Multiple Dates in a table - ugh!

**URL:** <https://www.ruby-forum.com/t/multiple-dates-in-a-table-ugh/85060>\
**Category:** Rails\
**Created:** [February 9, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/multiple-dates-in-a-table-ugh/85060 "2007-02-09T17:49:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [February 9, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/multiple-dates-in-a-table-ugh/85060/1 "2007-02-09T17:49:48Z")

</div>

Hi:

I have a table that has 3 datetime fields.

The first functions like a normal timestamp; I don’t handle it specially  
in my create

method, and it’s updated just fine. It’s called “created\_on”

The second is supposed to be a “last\_updated” field, as it’s important  
to know when

something was created and when it was last updated.

The third datetime field is meant to attach a user-defined date to the  
record in the table.

I’m trying to set the second two manually, with certain input. I can’t  
get either of them to

update. On the second, in my controller I’m trying:

@goal.last\_updated = Time.now

On the third, I’m trying to capture user input with (inside a form  
already):

\<%= f.date\_select :duedate %\>

Neither the second or the third are being updated in the table. What am  
i doing wrong?

Thanks so much in advance!

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [February 10, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/multiple-dates-in-a-table-ugh/85060/2 "2007-02-10T16:52:36Z")

</div>

Keynan P. wrote:

> the last\_updated field will be handled by rails automatically if you use  
> updated\_at/on however to solve the other problem more info would be a  
> help.
> 
> specifically  
> the controller/model/view that your working with

Keynan:

Thanks very much for your help. I’ve been able to get the “created\_on”  
and “last-updated” working now, but I still can’t get the “duedate”  
working. I wonder if it’s becuase the input that I’m feeding it is not  
a full timestamp, but only the date in various formats (even text input  
02/09/2007, e.g.)

That being said, here’s the relevant controller code:

```
@goal = Goal.new(params[:goal])

```

#store the userid for this goal  
@goal.entity\_id = session[:user].id  
@goal.last\_updated = Time.now

```
  if @goal.save
tags.each {|tag| @goal.tags << Tag.find_or_create_by_name(tag)}
@goalhist.goal_id = @goal.id
#big if for creating the actual measurements
@goalhist.save!
    flash[:notice] = 'Goal was successfully created.'
    #format.html { redirect_to goal_url(@goal) }
    format.html { redirect_to goals_path }
    format.xml { head :created, :location => goal_url(@goal) }
  else
    format.html { render :action => "new" }
    format.xml { render :xml => @goal.errors.to_xml }
  end
end

```

View:

\<%= f.date\_select :duedate %\>

No code in the model:

Again, any help you could provide would be great!

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [February 9, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/multiple-dates-in-a-table-ugh/85060/3 "2007-02-09T17:57:04Z")

</div>

the last\_updated field will be handled by rails automatically if you use  
updated\_at/on however to solve the other problem more info would be a  
help.

specifically  
the controller/model/view that your working with
