
The solution was to specify what the DateTimeKind was for the date being filtered. I know there is a way to tell a property that it is being saved as utc with the BsonDateTimeOptions DateTimeKind: I want the mongodb query to read all dates AS UTC instead of converting the dates retrieved to UTC.
C# CONVERT UNIX TIMESTAMP TO DATETIME DRIVER
Currently this solution does work, however I am looking for an alternative on the mongodb c# driver side. This seems like it is a lot of unnecessary work to filter the date on the grid. The reason I am converting the client to UTC, UTC to server then passing that date to the mongo query is because the client and server can be in different time zones. Return query.ToDataSourceResult(request) OrganizationGeography = person != null ? person.OrganizationGeography != null ? : string.Empty : string.Empty (o => !o.End.HasValue).Select(o => o.AddressLine1) : null : null, OrganizationCaseId = c.OrganizationCaseId,Īddresses = c.ClientTypeValue = ClientTypeValue.Person ? person.Addresses != null ? Join p in personCollection.AsQueryable() on c.ClientId equals p.Id into pĭisplayName = person != null ? person.LastName + ", " + person.FirstName : string.Empty, Query = (from c in casesCollection.AsQueryable() IMongoCollection personCollection = _db.GetCollection(_personCollection) Inside the client event before filtering I am capturing the date and converting it to utc:įor (var i = 0 i casesCollection = _db.GetCollection(_collection) Inside of the header of the grid I have a filter control to filter a date range. net core 2.1 with some telerik controls to display a grid.
C# CONVERT UNIX TIMESTAMP TO DATETIME HOW TO
How to pass UTC date from client to mongo db c# driver and filter? Is there anyway to prevent the mongodb c# driver from converting any date passed in a filter query to UTC but instead accept the date as UTC? IEnumerable testRange = getDateRange(startDate, endDate)

Public IEnumerable GetFullDaysInDateRange(DateTime startDate, DateTime endDate) This works well for most fields, but I don't know how to create a Unix Timestamp on the fly WITHIN the select statement:ĪrchiveCache = db.ArchiveValues.Select(x => new ArchiveElement() : full", date)) that will consecutively work with this cache also natively work with Unix Timestamps.įor the cache creation I want to select directly into an ArchiveElement. This is also useful because the frontend charts etc.

In order to keep the memory consumption low, I want to use a unix timestamp instead of a datetime object. There is this example code, but then it starts talking about millisecond / nanosecond problems. Now I want to read all rows into an array of objects of a simple class that I want to keep in memory for caching purposes. epoch - c datetime to unix timestamp milliseconds - How can I convert a Unix timestamp to DateTime and vice versa c datetime unix epoch / c / datetime / unix / data-conversion. The table structure is fixed, I can't change it.

Cast DateTime to Unix Timestamp in Select statement? - c# I do have a database table with millions of archived value rows that consist of a value (single), two integer id fields, and a datetime field (and some other fields that are not relevant for the cache I want to build).
