Home>

I want to compare the update_at of the data column with the current date and time

def edit
    if check_token (params [: ett])
      new
    else
      @title = 'expired'
      render json: @title
    end
  end

  def check_token (token)
    employees = EmployeesToken.find_by (token: token)
    return (employees.updated_at + 1.days)>= DateTime.now
  end

employees.updated_at + 1.day is
Tue, 26 Nov 2019 14:06:44 JST +09: 00
DateTime.now is
Thu, 28 Nov 2019 15:54:40 + 0900I can't compare two values ​​
return (employees.updated_at + 1.days)>= When processing DateTime.now, it will fall with an error.

I want to tell you if there are young people

  • Answer # 1

    return (employees.updated_at + 1.days) .to_datetime>= DateTime.now

Related articles