# Date Formats, assigning, viewing, validating, saving, changi

**URL:** <https://www.ruby-forum.com/t/date-formats-assigning-viewing-validating-saving-changi/103550>\
**Category:** Rails\
**Created:** [May 7, 2007, 8:29pm UTC](https://www.ruby-forum.com/t/date-formats-assigning-viewing-validating-saving-changi/103550 "2007-05-07T20:29:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonypm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a587f6/32.png) [@tonypm](https://www.ruby-forum.com/u/tonypm)\
**Post date:** [May 7, 2007, 8:29pm UTC](https://www.ruby-forum.com/t/date-formats-assigning-viewing-validating-saving-changi/103550/1 "2007-05-07T20:29:50Z")

</div>

Hi,

I know Date formats are a common topic, but I’ve spent most of the day  
googling and reading - and I cannot make things make sense.

I want to use European date format dd/mm/yy.  
I am happy to stick with the ISO format yyyy-mm-dd  
It is easy to display this in uk format using strftime(%d/%m/%Y)

Now all I need to do is simply fix the validation so that it switches  
the uk format to the ISO format.  
I was thinking of just using gsub to reverse the elements, but as I  
tried some examples I discovered some things that I cant explain and  
am hoping for some guidance.

(s.order\_date is a date attribute)  
using the console  
s=OrderDate.new

s.order\_date=“07-08-2008”  
s.order\_date.month=08 (seems to assume uk format)

s.order\_date=“07/08/2008”  
s.order\_date.month=07 (seems to assume us format)

I dont know why the two different formats are assumed. I cannot  
recall setting up anything to treat the nn-nn-nnnn format as uk  
format.

now if in the console, I enter s. The object with the textual date  
form is displayed.

So I thought I could fix the problem so that the user can enter / or -  
by substituting these before validation. BUT

If I enter s.order\_date=“31/08/2007”, I can still see the textual  
display but in the console, s.order\_date returns nil because the date  
format is invalid. I cant find a way to directly access the raw  
object field before it gets turned into a Date class. I need to get  
at the raw attribute value.

Is this the right approach, or am I missing something simple? I dont  
really want to add plugins unless I understand what they are changing,  
but it really seems simplest to me to use strftime to display and a  
simple before\_update method to fix the format.

Thanks for any help  
tonypm
