#versions = Version.find_all_by_created_at(2015-05-07)
#versions = []
datatype for created_at(datetime)
Please i want extract data by passing only date to a model .
I think it is simple
If you want to do it for the current date then you can just use Date.today
Version.where(created_at: Date.today.beginning_of_day..Date.today.end_of_day)
Otherwise as #davidesantangelo has mentioned that is fine, except using parsed "date" variable, you can use "date.beginning_of_day"
e.g.
selectDate = Date.parse('2015-05-07')
Version.where(created_at: selectDate.beginning_of_day..selectDate.end_of_day)
That will form query like this:
SELECT "versions".* FROM "versions"
WHERE ("versions"."created_at"
BETWEEN '2015-04-28 00:00:00.000000' AND '2015-04-28 23:59:59.999999')
And without "beginning_of_day" it will have query like
SELECT "users".* FROM "users"
WHERE ("users"."created_at"
BETWEEN '2015-04-28' AND '2015-04-28 23:59:59.999999')
So I would prefer it with beginning_of_day.
try this
date = Date.parse('2015-05-07')
and then
Version.where("created_at <= ? AND created_at >= ?", date + 1, date - 1)
Created at is a datetime so it would be very specific. You need to search within the same day
date = Date.parse('2015-05-07')
Version.where(created_at: date..date.end_of_day)
Related
I created the list of the dates between two dates (minimum and maximum) from another table where i compare the max date and today.
let
first = List.Min(#"Mizan (Banka&Kasa)"[Tarih]),
last = List.Max(
{(List.Max(#"Mizan (Banka&Kasa)"[Tarih])), Date.From(DateTime.LocalNow())}
),
howmanydays = Number.From(last) - Number.From(first) + 1,
Source = List.Dates(first, howmanydays, #duration(1, 0, 0, 0))
in
Source
But I am sure there must be an easier way to achieve this list.
Any ideas ?
Thats pretty much it, unless you prefer to omit howmanydays and use
Source = {Number.From(first) .. Number.From(last)}
then expand and convert format to date
If you want to create a table with the dates of another table maybe the best is:
CREATE NEW TABLE
date = CALENDAR(maxx(table_name, table_name[Date]),TODAY())
table_name is the table you want to select
table_name[Date] is the cell you want to get the last date
I am currently working with reports in Navision by a "book sales" currently use 2 variables "Date" one for the start and one for the end of the filter, but I wonder if you can only use a single variable where the user directly enter "month" and "year". Thank You!
If you are setting the filter with SETRANGE you need two values. But if you use SETFILTER you can use a string with a date filter like this:
010115..103115
p1..p3
and the just:
DateField.SETFILTER(filterstring);
Yes, when the user put the month and year data you by code transform this info in date values example:
Variables from and to = date
from := DMY2DATE(1, Month, Year);
EVALUATE(to, FORMAT(CALCDATE('+1M', Desde) -1));
YourTable.SETRANGE("Posting Date", from, to);
I have a table in Mongo. One of the fields is a DateTime. I would like to be able to get all of the records that are only for a single day (i.e. 9/3/2011).
If I do something like this:
var list = (from c in col
where c.PublishDate == DateTime.Now
select c).ToList();
Then it doesn't work because it is using the time in the comparison. Normally I would just compare the ToShortDateString() but NoRM does not allow me to use this.
Thoughts?
David
The best way to handle this is normally to calculate the start datetime and end datetime for the date in question and then query for values in that range.
var start = DateTime.Now.Date;
var end = start.AddDays(1);
...
But you'd also be well advised to switch to the official C# driver now. You should also use UTC datetimes in your database (but that gets more complicated).
I need to be able to display data for all date range and for the same date range but only for Saturdays.
Data stored in sql server.
Table:
DateTime Vlaue
Is it possible to create linq to sql query which would do that?
Or just select all for particular range and than on server side find all Saturdays?
What is the better way to do that?
You should be able to do something like this:
var results = Entities.YourTable.Where(r => r.SomeDate.DayOfWeek == DayOfWeek.Saturday);
I'd be inclined to just query the database once, then use linq to objects on the result set for the saturday data...
var values = db.Values.ToList(); // assuming your table is called values
var satValues = values.Where( v => v.TheDate.DayOfWeek == DayOfWeek.Saturday);
I have a table with many anniversaries : Date + Name.
I want to display the next anniversary and the one after with Linq.
How can i build the query ?
I use EF
Thanks
John
Just order by date and then use the .Take(n) functionality
Example with a list of some objects assuming you want to order by Date then Name:
List<Anniversaries> annivDates = GetAnnivDates();
List<Anniversaries> recentAnniv = annivDates.OrderBy(d => d.Date).ThenBy(d => d.Name).Take(2).ToList();
If the anniversaries are stored in regular DateTime structs, they may have the 'wrong' year set (i.e. wedding or birth year). I suggest writing a function which calculates the next date for an anniversary (based on the current day) like:
static DateTime CalcNext(DateTime anniversary) {
DateTime newDate = new DateTime(DateTime.Now.Year, anniversary.Month, anniversary.Day);
if (newDate < DateTime.Now.Date)
newDate = newDate.AddYear(1);
return newDate;
}
Then you proceed with sorting the dates and taking the first two values like described in the other postings:
(from e in anniversaries orderby CalcNext(e.Date) select e).Take(2)