1

I have a row that looks like the following (in a .xls):

bob    abc    6/14/14 8:23

I want to return the date and time as: 61414823

I tried to get started with:

def self.regex_date
_test_column = @sheet.row(1)[2].date
...
end

Which I read about here: How to retrieve date properly using spreadsheet gem in ruby

But I'm getting the following error, before I can get to the regex part:

in `regex_date': undefined method `date' for #<DateTime:0x007f94e111b700> (NoMethodError)
Community
  • 1
  • 1
MMP
  • 546
  • 2
  • 5
  • 19

1 Answers1

1

It means that @sheet.row(1)[2] is a DateTime object. It doesn't have .date method. Instead, you can use .to_date.

But I don't understand why do you want to convert it to Date. What you want is to use .strftime like this:

@sheet.row(1)[2].strftime("%-m%-d%y%-k%M")
DateTime.new(2014, 6, 14, 8, 23).strftime("%-m%-d%y%-k%M") # => "61414823"
Rustam Gasanov
  • 15,290
  • 8
  • 59
  • 72