Firestore timestamp the same day condition - google-cloud-firestore

I have the table with timestamp. I want to check timestamp with the same day date. If date is 21/06/2020, I want to get the same day records. That code does not work:
where("creation_date", "==", new Date())

I figured it out. Here is the code:
const startToday = new Date(),
endToday = new Date();
// Set up start date
startToday.setHours(0);
startToday.setMinutes(0);
startToday.setSeconds(0);
// Set up end date
endToday.setHours(23);
endToday.setMinutes(59);
endToday.setSeconds(59);
.where("creation_date", ">=", startToday)
.where("creation_date", "<=", endToday)

Related

DateRangePicker - Grey out unavailable dates

As the title suggests I am using DateRangePicker to add date ranges to an array. If possible I would like to be able to "grey" out already selected dates in the array. Is there anyway to do this?
Here is the solution to returning the dates in-between the range in case anyone else needs it.
List<DateTime> getDaysInBetweenIncludingStartEndDate(
{required DateTime startDateTime, required DateTime endDateTime}) {
// Converting dates provided to UTC
// So that all things like DST don't affect subtraction and addition on dates
DateTime startDateInUTC =
DateTime.utc(startDateTime.year, startDateTime.month, startDateTime.day);
DateTime endDateInUTC =
DateTime.utc(endDateTime.year, endDateTime.month, endDateTime.day);
// Created a list to hold all dates
List<DateTime> daysInFormat = [];
// Starting a loop with the initial value as the Start Date
// With an increment of 1 day on each loop
// With condition current value of loop is smaller than or same as end date
for (DateTime i = startDateInUTC;
i.isBefore(endDateInUTC) || i.isAtSameMomentAs(endDateInUTC);
i = i.add(const Duration(days: 1))) {
// Converting back UTC date to Local date if it was local before
// Or keeping in UTC format if it was UTC
if (startDateTime.isUtc) {
daysInFormat.add(i);
} else {
daysInFormat.add(DateTime(i.year, i.month, i.day));
}
}
return daysInFormat;
}
Yes, you can send disabled dates into the component.
Check this sample of the documentation.
For further options, check the whole docs.

how to convert a time eg- 22:00:00 to a timestamp + include next day date in Flutter

I want to ask how to convert a given time for example 22:00:00 into a timestamp and also add the next day date to it while converting into a time stamp in flutter.
Thank You
You can convert a Date string to a timestamp
convertDateTimeToTimestamp(String yourDateTime, [Duration? extraDuration]) {
DateTime date = DateTime.parse(yourDateTime);
if (extraDuration != null) {
date = date.add(extraDuration);
}
return date.microsecondsSinceEpoch;
}
then your example with one additional day (next day) can be:
main() {
final timestamp = convertDateTimeToTimestamp(
"2022-03-05 22:00:00",
Duration(days: 1),
);
print(timestamp); //output: 1646600400000000
// try to check the converted timestamp with addition duration in the example above, it's only one day
DateTime date = DateTime.fromMicrosecondsSinceEpoch(timestamp);
print('${date.year}-${date.month}-${date.day} ${date.hour}:${date.minute}:${date.second}'); //output: 2022-3-6 22:0:0
}
you can use intl package and format your datetime easier.
Timestamp data type is defined in cloud_firestore.
What do you mean by timestamp?

Flutter Firstore Timestamp now / current date

Below are all the Firebase timestamp methods that I have used and found handy.
How to get a Firestore timestamp (Todays date)
Timestamp timestampDate = Timestamp.now();
How to set a Timestamp from Datetime
DateTime someDate = DateTime.now();
Timestamp timestampDate = Timestamp.fromDate(DateTime(someDate.year, someDate.month, someDate.day))
How to get the Date object from Timestamp
DateTime dateTime = timestampDate.toDate();

Fetch month from data field in mongo db document

MongoCollection<Document> Person_List = db.getCollection("Person");
MongoCollection<Document> active_list = db.getCollection("activelist");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD");
String todaydate = format.format(new Date());
ArrayList<Document>
activeList=Person_List.find(Filters.regex("LastUpdate",todayDate.toString())).into(new
ArrayList<Document>());
This is the code what we have written, here we need to fetch the month from todaydate and need to compare with month of LastUpdate field, how to fetch the month from LastUpdate document field in mongo db, LastUpdate is the date string, can someone please help me.

Convert simple date into SQLite datetime format?

I have date in new Date() format. I need to convert to SQLite date time format.(2014-01-05T00:00:00.000Z). Is it possible to do so??
var date = new Date();
now I need to convert this date to SQLite datetime format like (2014-01-05T00:00:00.000Z).
Try:
var date = new Date();
var sqllite_date = date.toISOString();
Use this
// Create an instance of the Date class
var date = new Date();
// Convert it to an ISO string
var sqliteDate = Date.toISOString();
take a look at this W3schools
You can use strftime, from date and time functions.
SELECT strftime('%d-%m-%Y', 'now')
Output
10-06-2010
Hope this helps ..:)