# Date Parsing

**URL:** <https://rubytalk.org/t/date-parsing/46334>\
**Category:** ruby-talk\
**Created:** [7 May 2008 04:24 UTC](https://rubytalk.org/t/date-parsing/46334 "2008-05-07T04:24:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clement\_Ow](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Clement\_Ow](https://rubytalk.org/u/Clement_Ow)\
**Post date:** [7 May 2008 04:24 UTC](https://rubytalk.org/t/date-parsing/46334/1 "2008-05-07T04:24:48Z")

</div>

I have a script which I need to create a new Time or Date object to  
compare 2 dates for deletion. ie to delete files older than a stipulated  
date  
But i tend to get this error, undefined method 'parse' for  
DateTime:class or undefined method 'strptime'

Can anyone tell me what is wrong? A snippet of my code is as follows:

> **···**
>
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;folders.each do |folder|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dir.glob(folder+"/\*") do |file|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;match = regexp.match(File.basename(file))  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;match1 = regexp1.match(File.basename(file))  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matchExp = excep\_yyyymmdd.match(File.basename(file))  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matchExp1 = excep\_ddmmyyyy.match(File.basename(file))  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if match  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file\_date = DateTime.strptime(match[1])
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if matchExp != nil or matchExp1 != nil  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if $keepLastMthDay == true or $keepLastMth == true  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "File Escaped: #{file} (Keep last day of month option \>activated)"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif $keepLastMthDay == false and $keepLastMth == false  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if delete\_date \> file\_date  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size = (File.size(file))/1024  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deleted\_files \<\< fileData.new(file,size)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Files/Folders deleted: #{file} size: #{size} KB"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#FileUtils.rm\_r file  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end #if  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end #if  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif matchExp == nil or matchExp1 == nil  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if delete\_date \> file\_date  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size = (File.size(file))/1024  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deleted\_files \<\< fileData.new(file,size)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Files/Folders deleted: #{file} size: #{size} KB"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#FileUtils.rm\_r file  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end #if  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end # if matchExp
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud](https://avatars.discourse-cdn.com/v4/letter/7/57b2e6/32.png) [@7stud](https://rubytalk.org/u/7stud)\
**Post date:** [7 May 2008 06:50 UTC](https://rubytalk.org/t/date-parsing/46334/2 "2008-05-07T06:50:53Z")

</div>

Clement Ow wrote:

> I have a script which I need to create a new Time or Date object to  
> compare 2 dates for deletion. ie to delete files older than a stipulated  
> date  
> But i tend to get this error, undefined method 'parse' for  
> DateTime:class or undefined method 'strptime'
> 
> Can anyone tell me what is wrong? A snippet of my code is as follows:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;folders.each do |folder|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dir.glob(folder+"/\*") do |file|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;match = regexp.match(File.basename(file))  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;match1 = regexp1.match(File.basename(file))  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matchExp = excep\_yyyymmdd.match(File.basename(file))  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;matchExp1 = excep\_ddmmyyyy.match(File.basename(file))  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if match  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file\_date = DateTime.strptime(match[1])
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if matchExp != nil or matchExp1 != nil  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if $keepLastMthDay == true or $keepLastMth == true  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "File Escaped: #{file} (Keep last day of month option \>activated)"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif $keepLastMthDay == false and $keepLastMth == false  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if delete\_date \> file\_date  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size = (File.size(file))/1024  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deleted\_files \<\< fileData.new(file,size)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Files/Folders deleted: #{file} size: #{size} KB"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#FileUtils.rm\_r file  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end #if  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end #if  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif matchExp == nil or matchExp1 == nil  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if delete\_date \> file\_date  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size = (File.size(file))/1024  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deleted\_files \<\< fileData.new(file,size)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Files/Folders deleted: #{file} size: #{size} KB"  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#FileUtils.rm\_r file  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end #if  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end # if matchExp

strptime() is essentially undocumented, so I can't help you there. But  
here are some other ways to do what you want:

require 'parsedate.rb'  
require 'date'

str = "5/6/08"  
arr = ParseDate.parsedate(str, true) #true converts 08 to 2008  
date1 = Date.new(\*arr[0,3])

str2 = "2008-4-29"  
arr2 = ParseDate.parsedate(str2)  
date2 = Date.new(\*arr2[0,3])

if date2 \< date1  
&nbsp;&nbsp;puts "I want to delete this file"  
else  
&nbsp;&nbsp;puts "I don't want to delete this file"  
end

require 'scanf'

str3 = "2007.11.01"  
year, day, month = str3.scanf("%4d.%2d.%2d")  
date3 = Date.new(year, month, day)

if date3 \< date1  
&nbsp;&nbsp;puts "I want to delete this file"  
else  
&nbsp;&nbsp;puts "I don't want to delete this file"  
end

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Clement\_Ow](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Clement\_Ow](https://rubytalk.org/u/Clement_Ow)\
**Post date:** [7 May 2008 07:33 UTC](https://rubytalk.org/t/date-parsing/46334/3 "2008-05-07T07:33:05Z")

</div>

> &nbsp;&nbsp;puts "I don't want to delete this file"  
> end

Hi, thanks for that, did'nt know you can do it this way 😉  
However, I have 2 formats, one yyyymmdd and the other just ddmmyyyy(w/o  
any dashes). Unfortunately Parsedate cannot be used for ddmmyyyy. Only  
yyyymmdd can work. Any ideas?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Clement\_Ow](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Clement\_Ow](https://rubytalk.org/u/Clement_Ow)\
**Post date:** [7 May 2008 07:41 UTC](https://rubytalk.org/t/date-parsing/46334/4 "2008-05-07T07:41:56Z")

</div>

Clement Ow wrote:

> > &nbsp;&nbsp;puts "I don't want to delete this file"  
> > end
> 
> Hi, thanks for that, did'nt know you can do it this way 😉  
> However, I have 2 formats, one yyyymmdd and the other just ddmmyyyy(w/o  
> any dashes). Unfortunately Parsedate cannot be used for ddmmyyyy. Only  
> yyyymmdd can work. Any ideas?

or is there any way that we can convert something like ddmmyyyy to  
yyyymmdd so that it'll work when we use Date or parsedate to parse dates  
in order to not raise an invalid date error?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Heesob\_Park](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@Heesob\_Park](https://rubytalk.org/u/Heesob_Park)\
**Post date:** [7 May 2008 08:20 UTC](https://rubytalk.org/t/date-parsing/46334/5 "2008-05-07T08:20:05Z")

</div>

Hi,

Clement Ow wrote:

> Clement Ow wrote:
> 
> > > &nbsp;&nbsp;puts "I don't want to delete this file"  
> > > end
> > 
> > Hi, thanks for that, did'nt know you can do it this way 😉  
> > However, I have 2 formats, one yyyymmdd and the other just ddmmyyyy(w/o  
> > any dashes). Unfortunately Parsedate cannot be used for ddmmyyyy. Only  
> > yyyymmdd can work. Any ideas?
> 
> or is there any way that we can convert something like ddmmyyyy to  
> yyyymmdd so that it'll work when we use Date or parsedate to parse dates  
> in order to not raise an invalid date error?

[sidns@ns ~]$ irb  
irb(main):001:0\> require 'date'  
=\> true  
irb(main):002:0\> Date.strptime('20102008',"%d%m%Y").to\_s  
=\> "2008-10-20"  
irb(main):003:0\> Date.strptime('20081020',"%Y%m%d").to\_s  
=\> "2008-10-20"

Regards,  
Park Heesob

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud](https://avatars.discourse-cdn.com/v4/letter/7/57b2e6/32.png) [@7stud](https://rubytalk.org/u/7stud)\
**Post date:** [7 May 2008 08:27 UTC](https://rubytalk.org/t/date-parsing/46334/6 "2008-05-07T08:27:27Z")

</div>

Clement Ow wrote:

> Clement Ow wrote:
> 
> > > &nbsp;&nbsp;puts "I don't want to delete this file"  
> > > end
> > 
> > Hi, thanks for that, did'nt know you can do it this way 😉  
> > However, I have 2 formats, one yyyymmdd and the other just ddmmyyyy(w/o  
> > any dashes). Unfortunately Parsedate cannot be used for ddmmyyyy. Only  
> > yyyymmdd can work. Any ideas?
> 
> or is there any way that we can convert something like ddmmyyyy to  
> yyyymmdd so that it'll work when we use Date or parsedate to parse dates  
> in order to not raise an invalid date error?

Any string can be parsed using one of the examples I posted.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud](https://avatars.discourse-cdn.com/v4/letter/7/57b2e6/32.png) [@7stud](https://rubytalk.org/u/7stud)\
**Post date:** [7 May 2008 08:50 UTC](https://rubytalk.org/t/date-parsing/46334/7 "2008-05-07T08:50:21Z")

</div>

Heesob Park wrote:

> Hi,
> 
> Clement Ow wrote:
> 
> > Clement Ow wrote:
> > 
> > > > &nbsp;&nbsp;puts "I don't want to delete this file"  
> > > > end
> > > 
> > > Hi, thanks for that, did'nt know you can do it this way 😉  
> > > However, I have 2 formats, one yyyymmdd and the other just ddmmyyyy(w/o  
> > > any dashes). Unfortunately Parsedate cannot be used for ddmmyyyy. Only  
> > > yyyymmdd can work. Any ideas?
> > 
> > or is there any way that we can convert something like ddmmyyyy to  
> > yyyymmdd so that it'll work when we use Date or parsedate to parse dates  
> > in order to not raise an invalid date error?
> 
> [sidns@ns ~]$ irb  
> irb(main):001:0\> require 'date'  
> =\> true  
> irb(main):002:0\> Date.strptime('20102008',"%d%m%Y").to\_s  
> =\> "2008-10-20"  
> irb(main):003:0\> Date.strptime('20081020',"%Y%m%d").to\_s  
> =\> "2008-10-20"

$ irb  
irb(main):001:0\> require 'date'  
=\> true  
irb(main):002:0\> Date.strptime("20081020", "%Y%m%d").to\_s  
ArgumentError: invalid date  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/date.rb:650:in `new\_with\_hash'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/date.rb:675:in `strptime'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):2

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Heesob\_Park](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@Heesob\_Park](https://rubytalk.org/u/Heesob_Park)\
**Post date:** [7 May 2008 09:18 UTC](https://rubytalk.org/t/date-parsing/46334/8 "2008-05-07T09:18:19Z")

</div>

7stud -- wrote:

> Heesob Park wrote:
> 
> > Hi,
> > 
> > [sidns@ns ~]$ irb  
> > irb(main):001:0\> require 'date'  
> > =\> true  
> > irb(main):002:0\> Date.strptime('20102008',"%d%m%Y").to\_s  
> > =\> "2008-10-20"  
> > irb(main):003:0\> Date.strptime('20081020',"%Y%m%d").to\_s  
> > =\> "2008-10-20"
> 
> $ irb  
> irb(main):001:0\> require 'date'  
> =\> true  
> irb(main):002:0\> Date.strptime("20081020", "%Y%m%d").to\_s  
> ArgumentError: invalid date  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/date.rb:650:in `new\_with\_hash'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/date.rb:675:in `strptime'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):2

Ruby 1.8.4 fails but Ruby 1.8.6 works.

Regards,  
Park Heesob

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Clement\_Ow](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Clement\_Ow](https://rubytalk.org/u/Clement_Ow)\
**Post date:** [7 May 2008 09:20 UTC](https://rubytalk.org/t/date-parsing/46334/9 "2008-05-07T09:20:07Z")

</div>

7stud -- wrote:

> Heesob Park wrote:
> 
> > Hi,
> > 
> > Clement Ow wrote:
> > 
> > > Clement Ow wrote:
> > > 
> > > > > &nbsp;&nbsp;puts "I don't want to delete this file"  
> > > > > end
> > > > 
> > > > Hi, thanks for that, did'nt know you can do it this way 😉  
> > > > However, I have 2 formats, one yyyymmdd and the other just ddmmyyyy(w/o  
> > > > any dashes). Unfortunately Parsedate cannot be used for ddmmyyyy. Only  
> > > > yyyymmdd can work. Any ideas?
> > > 
> > > or is there any way that we can convert something like ddmmyyyy to  
> > > yyyymmdd so that it'll work when we use Date or parsedate to parse dates  
> > > in order to not raise an invalid date error?
> > 
> > [sidns@ns ~]$ irb  
> > irb(main):001:0\> require 'date'  
> > =\> true  
> > irb(main):002:0\> Date.strptime('20102008',"%d%m%Y").to\_s  
> > =\> "2008-10-20"  
> > irb(main):003:0\> Date.strptime('20081020',"%Y%m%d").to\_s  
> > =\> "2008-10-20"
> 
> $ irb  
> irb(main):001:0\> require 'date'  
> =\> true  
> irb(main):002:0\> Date.strptime("20081020", "%Y%m%d").to\_s  
> ArgumentError: invalid date  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/date.rb:650:in `new\_with\_hash'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/date.rb:675:in `strptime'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):2

hmmm. i even tried in irb whenever i use parse, it gives me an error:

Date.strptime('20081020',"%Y%m%d")  
undefined method `strptime' for Date:Class (NoMethodError)

Date.parse('20081020',"%Y%m%d").to\_s  
undefined method `parse' for DateTime:Class (NoMethodError)

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Clement\_Ow](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@Clement\_Ow](https://rubytalk.org/u/Clement_Ow)\
**Post date:** [7 May 2008 09:46 UTC](https://rubytalk.org/t/date-parsing/46334/10 "2008-05-07T09:46:58Z")

</div>

Clement Ow wrote:

> Date.strptime('20081020',"%Y%m%d")  
> undefined method `strptime' for Date:Class (NoMethodError)
> 
> Date.parse('20081020',"%Y%m%d").to\_s  
> undefined method `parse' for DateTime:Class (NoMethodError)

and im running ruby 1.8.5.. could it be why this has a prob? Like a bug  
or something?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Heesob\_Park](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@Heesob\_Park](https://rubytalk.org/u/Heesob_Park)\
**Post date:** [7 May 2008 10:14 UTC](https://rubytalk.org/t/date-parsing/46334/11 "2008-05-07T10:14:35Z")

</div>

Clement Ow wrote:

> Clement Ow wrote:
> 
> > Date.strptime('20081020',"%Y%m%d")  
> > undefined method `strptime' for Date:Class (NoMethodError)
> > 
> > Date.parse('20081020',"%Y%m%d").to\_s  
> > undefined method `parse' for DateTime:Class (NoMethodError)
> 
> and im running ruby 1.8.5.. could it be why this has a prob? Like a bug  
> or something?

I guess you missed  
require 'date'

Regards,  
Park Heesob

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7stud](https://avatars.discourse-cdn.com/v4/letter/7/57b2e6/32.png) [@7stud](https://rubytalk.org/u/7stud)\
**Post date:** [7 May 2008 19:09 UTC](https://rubytalk.org/t/date-parsing/46334/12 "2008-05-07T19:09:19Z")

</div>

Clement Ow wrote:

> Clement Ow wrote:
> 
> > Date.strptime('20081020',"%Y%m%d")  
> > undefined method `strptime' for Date:Class (NoMethodError)
> > 
> > Date.parse('20081020',"%Y%m%d").to\_s  
> > undefined method `parse' for DateTime:Class (NoMethodError)
> 
> and im running ruby 1.8.5.. could it be why this has a prob? Like a bug  
> or something?

It appears that Date.parse() and Date.strptime() are/were broken, and  
therefore the defacto means for parsing Dates from Strings are the  
Standard Library modules: ParseDate and Scanf. For instance, "The  
Ruby Way" doesn't even mention Date.parse() or Date.strptime() when  
discussing how to get Dates from Strings. And pickaxe2 doesn't cover  
the Date/Time subject at all.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [22 May 2008 18:21 UTC](https://rubytalk.org/t/date-parsing/46334/13 "2008-05-22T18:21:11Z")

</div>

require 'date'

Nothing is broken.

Kirk Haines

> **···**
>
> On Thu, 8 May 2008, 7stud -- wrote:
> 
> > Clement Ow wrote:
> > 
> > > Clement Ow wrote:
> > > 
> > > > Date.strptime('20081020',"%Y%m%d")  
> > > > undefined method `strptime' for Date:Class (NoMethodError)
> > > > 
> > > > Date.parse('20081020',"%Y%m%d").to\_s  
> > > > undefined method `parse' for DateTime:Class (NoMethodError)
> > > 
> > > and im running ruby 1.8.5.. could it be why this has a prob? Like a bug  
> > > or something?
> > 
> > It appears that Date.parse() and Date.strptime() are/were broken, and  
> > therefore the defacto means for parsing Dates from Strings are the  
> > Standard Library modules: ParseDate and Scanf. For instance, "The  
> > Ruby Way" doesn't even mention Date.parse() or Date.strptime() when  
> > discussing how to get Dates from Strings. And pickaxe2 doesn't cover  
> > the Date/Time subject at all.
