
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
- Looking for Partner
I'm looking for partner for long-term collaborating. Of course, I'll pay for you. If you are interested, Please DM me.
- Hola equipo de soporte,
Hola equipo de soporte, Estoy desarrollando una Function en Appwrite Cloud con Node.js 22 y el siguiente package.json: { "name": "upload-whitelist", "type"...
- Looking for Partner
I'm looking for partner for long-term collaborating. Of course, I'll pay for you. If you are interested, Please DM me.
