ruby on rails - How to extract only year from created_at column -


querying database created_at value gives following output:

>> kevin.created_at => sun, 21 aug 2016 07:46:26 utc +00:00 

how can extract year information?
tried treat kevin.created_at string , see if want with:

>> kevin.created_at.split[3].to_i 

however message:

nomethoderror: undefined method `split' sun, 21 aug 2016 07:46:26 utc +00:00:time 

therefore tried with:

>> kevin.created_at.to_a => [26, 46, 7, 21, 8, 2016, 0, 234, false, "utc"] 

so may have solution with:

>> kevin.created_at.to_a[5] => 2016 

is there better or more elegant solution query postgresql information?

you can use .year function ruby time class as:

kevin.created_at.year 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -