little prob with Date.strptime

J

Junkone

hello
for some reason, the Date.strptime is mixing up my date. pl see here.
the date changs from "6/13/2008" to "2020-06-13"

irb(main):001:0> require 'date'
=> true
irb(main):006:0> entry="6/13/2008"
=> "6/13/2008"
irb(main):007:0> Date.strptime(entry,'%m/%d/%y')
=> #<Date: 4918027/2,0,2299161>
irb(main):008:0> nowdate=Date.strptime(entry,'%m/%d/%y')
=> #<Date: 4918027/2,0,2299161>
irb(main):009:0> nowdate.to_s
=> "2020-06-13"
 
S

snex

hello
for some reason, the Date.strptime is mixing up my date. pl see here.
the date changs from "6/13/2008" to  "2020-06-13"

irb(main):001:0> require 'date'
=> true
irb(main):006:0> entry="6/13/2008"
=> "6/13/2008"
irb(main):007:0> Date.strptime(entry,'%m/%d/%y')
=> #<Date: 4918027/2,0,2299161>
irb(main):008:0> nowdate=Date.strptime(entry,'%m/%d/%y')
=> #<Date: 4918027/2,0,2299161>
irb(main):009:0> nowdate.to_s
=> "2020-06-13"

you ned %Y, not %y (note the capitalization). im guessing that since
%y means yy, its only taking the first 2 digits of your year (20) and
using that as the year.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top