
Hello. I am having issue with the dates in appwrite. For some reason, the date are printing out one day before the current day.
Here is code:
const today = new Date();
const formattedToday = today.toDateString().slice(4); // Format the date as "MM-DD-YYYY"
console.log(formattedToday);
const todayPosts = entries.documents
.filter((post) => {
const postDate = new Date(post.LaunchDate);
console.log(postDate);
console.log('____________________');
const formattedPostDate = postDate.toDateString().slice(4); // Format the date as "MM-DD-YYYY"
console.log('Formatted: ' +formattedPostDate);
return formattedPostDate === formattedToday; // Filter posts with matching formatted date
})
.sort((a, b) => b.Upvotes.length - a.Upvotes.length);
const posts = entries.documents.sort(
// sort the posts based on the number of upvotes
(a, b) => b.Upvotes.length - a.Upvotes.length
);

The date you're receiving are UTC

oh

I want to create somth like how product hunt has

like how they show the current products of the day

So you can add the hours (or subtract) to match your timezone

Ohh cool

but unsure how


When searching you should also match the timezone to UTC

like this?

const today = new Date();
console.log(today);
const formattedToday = today.toISOString().slice(0, 10); // Format the date as "YYYY-MM-DD"
console.log(formattedToday);
const todayPosts = entries.documents
.filter((post) => {
const postDate = new Date(post.LaunchDate);
const formattedPostDate = postDate.toISOString().slice(0, 10); // Format the date as "YYYY-MM-DD"
console.log(formattedPostDate);
return formattedPostDate === formattedToday; // Filter posts with matching formatted date
})
.sort((a, b) => b.Upvotes.length - a.Upvotes.length);
const posts = entries.documents.sort(
// sort the posts based on the number of upvotes
(a, b) => b.Upvotes.length - a.Upvotes.length
);

Are you using Appwrite database?

Yes

The post.launchdate

It's from appwrite

Is this against the cloud?

Or latest Appwrite version?

Wym

Is it self-hosted or Appwrite cloud?

I'm using appwrite cloud

So for example if you have collection named votes, and you want to get all of those in the current day you can do this:
try{
const start = new Date();
start.setUTCHours(0,0,0,0);
const end = new Date();
end.setUTCHours(23,59,59,999);
const docs = await documents.listDocuments('db_id','c_id',[
Query.greaterThan('LaunchDate',start.toISOString()),
Query.lessThan('LaunchDate',end.toISOString()),
]);
} catch (e) {
// Mmm something went wrong,
}

This will return all documents where LaunchDate
match this dates.

In the self-hosted version 1.3.x
+ you can use a shorthand of Query.between
You read about it here: https://dev.to/appwrite/join-celebrations-appwrite-13-ships-relationships-57fc

Oh
Recommended threads
- Appwrite Cloud Custom Domains Issue
I’m trying to configure my custom domain api.kondri.lt (CNAME pointing to appwrite.network., also tried fra.cloud.appwrite.io with no luck ) but encountering a ...
- Persistent 401 Unauthorized on all authe...
Hello, I'm facing a critical 401 Unauthorized error on my admin panel app and have exhausted all debugging options. The Problem: When my React app on localhos...
- OpenAI Whisper on Appwrite Sites
Hey guys, just wondering if I can serve an OpenAI Whisper AI on appwrite / appwrite sites. tiny model is like ~40-50MB
