i would like to know how to structure a timestamp field in Firestore in order to do specific queries like:
Get all the documents with the same hour in a month
Retrieve timestamp from firebase and compare with required hour.If document matches add the document to an array.Finally after comparing with all documents your array contains only documents with same hour in a month
Date month = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(month.getTime());
calendar.add(Calendar.MONTH, -6);
final String date = String.valueOf(document.get("OrderPlacedDateTime"));
if(date.contains((CharSequence) year)) {
//add to array
}
I did this in android idea might be helpful.
Related
Like I have a group of data of different dates and I want to have data between two particular date like start date and end date and I want data between these two dates. And I don't really have any idea how to do so can I get any insight about it..
const start_date = new Date(item.start_date).getTime();
const end_date = new Date(item.end_date).getTime();
const diff = end_date - start_date;
Now you have the different of two dates in timestamp type. You can check here for more information about timestamp https://en.wikipedia.org/wiki/Unix_time
MS Access 2016,
I have Multiple queries - approximately 120 - that are gathering temp history based on date criteria that I currently update manually for each query - >=#8/1/2021# And <#9/1/2021# - for the month of August 2021.
What would be the best solution to update this in one place so all queries could refer to that one date range?
Sample Query: (Usually 43 parameter points)
SELECT
History1HourAverage.TimeStamp,
History1HourAverage.Parameter001,
History1HourAverage.Value001,
History1HourAverage.Parameter002,
History1HourAverage.Value002,
History1HourAverage.Parameter003,
History1HourAverage.Value003,
History1HourAverage.Parameter004,
History1HourAverage.Value004
FROM History1HourAverage
WHERE
(
(
***(History1HourAverage.TimeStamp)>=#8/1/2021#
AND (History1HourAverage.TimeStamp)<#9/1/2021#
)***
AND ((History1HourAverage.Parameter001)="10S8MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter002)="10S9MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter003)="10S10MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter004)="10S11MApp.nvoSpaceTemp")
);
Thank you
A couple of options:
Either
Add a table called DateRange with two fields, StartDate and EndDate. Enter one record in that table with the date range that you want to use for your queries. Edit each of your queries and include the DateRange table. Set the criteria for the query to WHERE History1HourAverage.TimeStamp >= DateRange.StartDate And History1HourAverage.TimeStamp < DateRange.EndDate
Alternatively
Create a VBA module with two functions
Public Function StartDate() As Date
StartDate = #8/1/2021#
End Function
Public Function EndDate() As Date
EndDate = #9/1/2021#
End Function
Set your query criteria for the query to WHERE History1HourAverage.TimeStamp >= StartDate() And History1HourAverage.TimeStamp < EndDate()
When you want to use a different date range you either (1) edit the data in DateRange table, or (2) edit your functions to return the new dates.
I have some time based data in a table which has a schema like this :
Timestamp |id | Name | Marks
Timestamp represents data from a day per week in the year when exams
are held. Example : 5 exam weeks every year for 5 students would have
5 timestamps for same set of students.
id is a unique key associated with each student.
I have used the Partition Key as Timestamp ( as I am
interested in figuring out performance of the class on an exam in a
particular week.
I have used the id as the row key( not important in my case as I dont use it to filter)
Now, in the client application, I am fetching the data by partition key (timestamp) and adding an
additional layer to process details of every student. I am having to do this for every student in the university (which is a huge number of students.)
I am wondering if there is a better way to fetch these results(basically reduce number of calls) by batching the row keys in each call to filter by partition key ?
Example : Since I am looking for the data from a single week at a time, it just has one date . and that date is the partition key. Lets say there are 10000 students who appeared in an exam today. I dont want to make 10K calls to Cosmos DB to give me their marks. Instead , since we are looking at the same partition, is there a way to make <10K calls by filtering out rows that are not required?
Example:
Expect that your partition key (Timestamp) value is: A
and your student ids are b1,b2,b3,b4
Now if your want to query only A for student b1 and b3 you can write:
SELECT * FROM c WHERE c.Timestamp = 'A' AND (c.id = 'b1' OR c.id = 'b3')
You can also apply GROUP BY on Timestamp if this will help in the result.
Receiving these values:
Via SDK v3:
private async Task QueryItemsAsync()
{
// sql query
var sqlQueryText = "SELECT * FROM c WHERE c.Timestamp= 'A' and (c.id = 'b1' or c.id = 'b3')";
// also supports Linq
var queryDefinition = new QueryDefinition(sqlQueryText);
var queryResultSetIterator = this.container.GetItemQueryIterator<Exam>(queryDefinition);
var exams = new List<Exam>();
while (queryResultSetIterator.HasMoreResults)
{
FeedResponse<Exam> currentResultSet = await queryResultSetIterator.ReadNextAsync();
foreach (var exam in currentResultSet)
{
exams.Add(exam);
}
}
return exams;
}
I have a computed field in which I am displaying total number of documents in a view that meet the criteria. I am using GetAllEntriesByKey and want to pass start date, end date and a name field value as search key string. is there a efficient method to get the result.
Create a view with
first sorted/categorized column with date
second sorted/categorized column with name
Get the entries with
var v:NotesView = database.getView("yourView");
var query = new java.util.Vector();
var startDate:Date = new Date(2017,1,1);
var endDate:Date = new Date(2017,2,31);
var range:NotesDateRange = session.createDateRange(startDate, endDate);
query.addElement(range);
query.addElement("searchName");
var vec:NotesViewEntryCollection = v.getAllEntriesByKey(query, true);
(Note for second parameter in Date(): January is 0, February is 1, and so on.)
You could make the first three columns of the view all sorted columns (start date, end date, name).
The Keys parameter for GetAllEntriesByKey can be an array (Vector in Java)
Set the keys array to have the first entry as the start date, second as end date, third as name.
I have a date of joining field as doj (type : Date) in my MongoDB collection. I want to find the records of all employees who joined more than a month before from today. However it is giving any record where the doj is just even one day greater than the one month old date from today. I am not getting the one month older doj from today. Please help me with the mistakes that I am making.
I am using the following code :
var dt = new Date();
dt.setMonth(dt.getMonth() - 1);
collection.find({doj: {$gt:dt}}, function(error, docs) {
docs.forEach(function (doc) {
console.log("DOJ = "+ doc.doj);
}
});
If you want records with date of joining older then one month ago, you should query for {doj: {$lt:dt}}