Change 1-06-2006 to 1st July 2006 (date formatting)


#1

Hi,

I have a few dates coming from the datebase in the format ‘DD-MM-YYYY’

How can I change this in to a more human readable format?

such as 1st July 2006

Thanks
Scott


#2

scott wrote:

See Time#strftime.

Regards,

Dan


#3

Daniel B. wrote:

scott wrote:

I have a few dates coming from the datebase in the format ‘DD-MM-YYYY’

How can I change this in to a more human readable format?

See Time#strftime.

Just in case you haven’t got it bookmarked yet, you can see
Time#strftime
(and a lot of other Ruby you’re going to have questions about) at:

http://www.rubycentral.com/book/ref_c_time.html

The search capabilities at rubycentral have been a source of motivation
for
some and there are sites that offer the same content with additional
capabilities. A couple are (and there are others)

http://www.ruby.ch/en/rubybookonline.shtml

http://www.ruby-doc.org/docs/ProgrammingRuby/

I find these and other sites more helpful after having bought the book
itself, and still very often just grab the book when I’m thinking
through
how to tackle a challenge.

hth,
Bill


#4

thanks for the links, totally new to ruby, so they should come in useful

After a bit of reading I have managed to get this to work

<%date = Time.now %>
<%= date.strftime("%d %B %Y") %>

the Value @pMin = yyyy-mm-dd eg 2006-06-06

how can I put this in to a time obeject to use the strftime function
with it?

Thanks
Scott


#5

Hi Scott,

scott wrote:

the Value @pMin = yyyy-mm-dd eg 2006-06-06

how can I put this in to a time obeject to use
the strftime function with it?

I think you’ll find what you want at http://api.rubyonrails.org in the
ActiveSupport::CoreExtensions::date::Conversions module.

hth,
Bill