Model in Rails application
created_atI want to find the date difference using.
lastday = Date.new (2020, 12, 31) lastday --Date.today =>(71/1)
What you can't do (what I want to achieve)
As mentioned above, if the type is Date, you can find the number of days,
create_atThe type may be different, so I can't find it.
created_atUse to find the date difference
created_atTo the same type as Date (I think it can be calculated if the type is the same)
I would appreciate it if you could teach me.
I look forward to working with you.
Answer # 1
Ruby time classes can be subtracted.
Since you can see the number of seconds of the difference, I think you should divide it by the number of seconds in a day (1.days is OK).
Time.zone.now --Model.first.created_at =>6949.569539191 past_seconds = Time.zone.now --Model.first.created_at past_days = (past_seconds/1.days) .floor
- ruby on rails - i'm using payjpjs v2 i want to register the card name
- ruby on rails 5 - star evaluation using raty stars become very large
- [ruby on rails] i want to display a parent model that matches the information of the associated child model
- ruby on rails - i can't comment out using htmlerb begin
- ruby on rails - returns a value from the rails model to the controller
- ruby on rails - no data when using v-if
- ruby on rails - i can't create a model with rails
- ruby on rails - about deploying apps using s3 function
- [ruby on rails 6] i implemented the tag function using acts-as-taggable-on, but i can't jump to the linked article from the list
- ruby - i want to get it at intervals by searching using rails active record
- ruby on rails - i want to validate only the foreign key on the model side
- ruby on rails - the link between the model created by devise and the model originally created does not work
- ruby on rails - rails associated model is not saved in db
- ruby on rails - [rails 6] i'm using bootstrap 4, but the layout collapses only after logging out
- [ruby on rails] how to write when getting a model nested in multiple stages with includes
- ruby on rails 5 - i don't understand the difference between model and controller methods
- ruby - about routing using rails collection
- ruby on rails - [rails] i want to define routing using the resources method
- ruby - i want to solve the n + 1 problem when using rails where method in loop processing
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- i want to check the type of a shell script variable