# Formatting dates for database, in controller or model

**URL:** <https://www.ruby-forum.com/t/formatting-dates-for-database-in-controller-or-model/170941>\
**Category:** Rails\
**Created:** [June 24, 2009, 10:09am UTC](https://www.ruby-forum.com/t/formatting-dates-for-database-in-controller-or-model/170941 "2009-06-24T10:09:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lars\_Smit](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3bc359/32.png) [@Lars\_Smit](https://www.ruby-forum.com/u/Lars_Smit)\
**Post date:** [June 24, 2009, 10:09am UTC](https://www.ruby-forum.com/t/formatting-dates-for-database-in-controller-or-model/170941/1 "2009-06-24T10:09:33Z")

</div>

I use the jQuery datepicker widget and the date is formatted in this  
format in the input field after picking a date: dd/mm/yy. I have to  
format the date for saving to the database and I made an method that  
converts the date in my controller. This works fine but my senses are  
telling me I have to do that in the model. How I do that? I’m playing  
with before\_update and before\_save, but how does this work with  
update\_attributes?

Code:

```
@fund = InvestmentFund.find params[:investment_fund][:id]
params[:investment_fund][:start_date] = format_date_jquery_db

```

(params[:investment\_fund][:start\_date])

and then I save with update\_attributes
