I need to find all records created on a specific day of the week. I only have a standard date available to me. How do I do this in activerecord?
You can use the DAYOFWEEK function in MySQL and pass it to the: conditions parameter. Suppose you have a model called Item, this will return all items created on Sunday:
Item.all (: conditions => ['dayofweek (created_at) =?', 1])
Using Postgres, you can do something similar with to_char .
, , , , MySQL . , , , .
where("extract(dow from created_at) = ?", Date.today.wday)
, postgres. , , . , , , .
Unix Epoch. Time.to_i Ruby.
Time.to_i
7 ( 0 6).
dayOfWeek = (epochseconds / 86400 ) % 7;
Source: https://habr.com/ru/post/1776730/More articles:MEF to load DLL one after another - c #Set JSP location for servlet - javaConverting multiple method overloads to a general method, a design issue - genericsAndroid ListView scrollTo - androidHow stable is Guice 3.0 Beta - javaXMLHttpRequest answer has no headers in Internet Explorer - javascriptПриложение .NET прекращает работу, не входя в AppDomain.UnhandledException - .netHow to get the form to be sent to the input key only when the user focuses on the input login? - javascriptВ чем смысл объявления doctype в верхней части html-формы? Что-то меняет? - htmlVS2010 Debugging: displaying datatip without mouse (use keyboard)? - visual-studio-2010All Articles