Problem with date format

Hi Everybody,

I have some issue with date formats.

Like I using calender select plugin to select date, It will return the
date with US format like “MM-DD-YYYY”.

If I save this in mysql table, it stores like “YYYY-MM-DD”

12-31-2007 (31st Dec 2007) stored in MYSQL like 2007-31-12 ( Actually
NULL cos 12 th day, 31 st month and 2007).

Like I cant store the date 12-31-2007 in US format in MYSQL table.

Any suggestion appreciated.

Regards,
T.Veeraa.

On 12/14/07, Veera S. [email protected] wrote:

12-31-2007 (31st Dec 2007) stored in MYSQL like 2007-31-12 ( Actually
NULL cos 12 th day, 31 st month and 2007).

Like I cant store the date 12-31-2007 in US format in MYSQL table.

Databases store dates in YYYY-MM-DD format so that operations like
sorting by date work properly.

But why do you care. ActiveRecord will convert to and from ruby Time
or DateTime objects and you can format them for display as you wish,
no matter how they are stored in the DB.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Lets try and make this easier for the OP to read…

You don’t need to worry how the date is stored in the tables. You are
not going to access the tables directly (unless you need another
external app interacting with the same database). You are going to
access them trough Models.

When a model has a method that relates to a date column, it is going
to return a Date object.

When a model has a method that relates to a datetime column, it is
going to return a Time object.

So, lets say you have an Order model (that relates to the Orders
table) and this Order model has a shipped_at attribute (relates to the
shipped_at datetime column in your database). You can store the data
on this attribute by using “@order.shipped_at = Time.now”. If you need
to read this datetime to show to the user in a view, you can use
@order.shipped_at.to_formatted_s(:short)”. This will generate
something readable.

For more help generating different Time objects, use:

http://ruby-doc.org/core/classes/Time.html

Several examples are shown in AWDWR and on this group.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs