
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
- Messaging via Resend: "to": "\"undisclos...
I'm using the node-appwrite@18.0.0 SDK. ``` await messaging.createEmail({ messageId: ID.unique(), subject: "Subject", content: `htmlCont...
- Internal 500 Server Error
I don't have much information but I am unable to create anything on database, Auth users are creating but not able to fetch into database
- CORS + 401 Error with Appwrite Authentic...
I'm getting a CORS + 401 Error with Appwrite Authentication Access to fetch at 'https://cloud.appwrite.io/v1/account/sessions/email' from origin 'https://my-c...
