Search code examples
ruby-on-railsrubyjulian-date

Ruby 2/Rails 4 - How to get Julian Date of "created_at"


I am trying to generate an incident_number in my Incident model as follows:

  def incident_number
    (self.created_at.strftime("%Y") + self.created_at.jd.to_s + self.id.to_s).to_i
  end

I am receiving an error that "jd" is an undefined method.

I can call Date.Today.jd to get the Julian Date of today, but how do I get the Julian Date of the "created_at" date?

Thanks in advance.


Solution

  • You have to convert the created_at to Date type of an object:

    self.created_at.to_date.jd.to_s