How to get dd mmm and yyyy from dd-mmm-yyyy


#1

The input values could be something like this:
01-Dec-2006
01-December-2006
1-June-2006

Is there an easy to way to get the three variables populated dd, mmm and
yyyy for any of the above input values? I tried to look at regex but
couldn’
anything simple.

Thanks


#2

Neeraj K. wrote:

The input values could be something like this:
01-Dec-2006
01-December-2006
1-June-2006

Is there an easy to way to get the three variables populated dd, mmm and
yyyy for any of the above input values? I tried to look at regex but
couldn’
anything simple.

http://ruby-doc.org/core/classes/String.html#M001875

‘01-December-2006’.split ‘-’


Matthew B. :: removed_email_address@domain.invalid
Resume & Portfolio @ http://madhatted.com


#3

On Jun 5, 2006, at 01:15 PM, Matthew B. wrote:

anything simple.

http://ruby-doc.org/core/classes/String.html#M001875

‘01-December-2006’.split ‘-’

Which would return an Array object. If you wanted to easily have the
values sent to your three variables, you can do:

dd, mmm, yyyy = ‘01-December-2006’.split ‘-’

-Brian


#4

Neeraj K. wrote:

The input values could be something like this:
01-Dec-2006 1-June-2006
01-December-2006
1-June-2006

Is there an easy to way to get the three variables populated dd, mmm and
yyyy for any of the above input values? I tried to look at regex but
couldn’
anything simple.

Hi, sorry for the late reply. ParseDate.parsedate(string) will do what
you are looking for. There’s some documentation here:

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

(open the page and then find parsedate)

For example, in irb:

irb(main):004:0> require ‘parsedate’
=> false
irb(main):005:0> s1 = ‘01-Dec-2006’
=> “01-Dec-2006”
irb(main):006:0> s2 = ‘01-December-2006’
=> “01-December-2006”
irb(main):007:0> s3 = ‘1-June-2006’
=> “1-June-2006”
irb(main):008:0> a1 = ParseDate.parsedate(s1)
=> [2006, 12, 1, nil, nil, nil, nil, nil]
irb(main):009:0> y1, m1, d1 = ParseDate.parsedate(s1)
=> [2006, 12, 1, nil, nil, nil, nil, nil]
irb(main):010:0> y1
=> 2006
irb(main):011:0> m1
=> 12
irb(main):012:0> d1
=> 1
irb(main):013:0> a2 = ParseDate.parsedate(s2)
=> [2006, 12, 1, nil, nil, nil, nil, nil]
irb(main):014:0> a3 = ParseDate.parsedate(s3)
=> [2006, 6, 1, nil, nil, nil, nil, nil]

regards

Justin