Forum: Ruby little prob with Date.strptime

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5044d0567cc7ae2e52cbd511958e2c15?d=identicon&s=25 Junkone (Guest)
on 2009-02-27 22:29
(Received via mailing list)
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"
D0ac5c9608854166a5483061a169405e?d=identicon&s=25 snex (Guest)
on 2009-02-27 22:50
(Received via mailing list)
On Feb 27, 3:22 pm, Junkone <junko...@gmail.com> wrote:
> 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.
This topic is locked and can not be replied to.