#Get server timestamp

34 messages · Page 1 of 1 (latest)

quiet flint
#

Is there any method/function to get appwrite server time??

I want to compare the time remaining to unban user with expiry timestamp using server timestamp.

timid sandal
quiet flint
#

I need to create a collection for this

#

Ok which function will u use?

timid sandal
#

What are you exactly trying to achieve?

#

Just to have a better idea and suggest you how to handle it in a more direct way 😅

quiet flint
#

I want to ban users and set expiry time in the database like unban after 1 hr, 5hr...etc

and also want to compare how many hrs, mins or seconds left in unban and i don't want to compare timestamp with user's local time because users can manipulate their device time.

#

Simplify: banned_time:'', expiry:banned_time+5hours

timid sandal
#

It will use server time so you will not need to worry about manipulation

quiet flint
#

But it is not fixed to only hours also sometimes I need in minutes, so there will be so many functions execution each mins
Ok thanks

#

so I need to do it like this??

#

try {
await appwriteDatabases
.createDocument(
DATABASE_ID,
BANNED_USERS_COLLECTION_ID,
getUser.$id,
{
user: getUser.$id,
created: "",
reasons: "Violence",
}
)
.then(async (data) => {
const originalDateTime = new Date(data.created);

        const updatedDateTime = new Date(
          originalDateTime.getTime() + 5 * 60 * 60 * 1000
        );

        await appwriteDatabases.updateDocument(
          DATABASE_ID,
          BANNED_USERS_COLLECTION_ID,
          getUser.$id,
          {
            expiry: updatedDateTime,
          }
        );
      });
    log("banning_done2");
  } catch (updateDocumentError) {
    log("Update document error:", updateDocumentError);
  }
timid sandal
quiet flint
#

There is problem when creating new doc or update existing doc with same Id, Is there upsertDocument available in appwrite.
I manually need to check if doc exist ?update :create doc

bitter anvil
quiet flint
#

But there should be a function like appwrite.getTimestamp(), If I want to fetch some docs from now to in the past in client side using query but using functions is complicated.

timid sandal
#

To override the timing cooldown

#

That's why I recommend handling all with an Appwrite function so since it's being created server sided, it will not be possible to manipulate it to unban the user sooner than at the expected time

quiet flint
#

No i have asked to fetch some docs for example posts from now to in the past

timid sandal
#

I understand. I thought it was to ban as said. In such case, you could get too with a function it. This seems an interesting request so I recommend to create a post in the appwrite GitHub

timid sandal
bitter anvil
quiet flint
# bitter anvil you don't need to get the server time

Ok, for example I need posts list of past 1 week and for this small task small query is enough like

appwrite.listDocs(...,
[
Query.greaterThan(
'created',
new Date(appwrite.serverTimestamp().setDate(appwrite.serverTimestamp().getDate() - 7)
)
]
);

why to create cloud function??

bitter anvil
bitter anvil
quiet flint
#

But user can manipulate it you can check it on your Android

bitter anvil
#

So what

quiet flint
#

By Changing date of device also if I use utc

bitter anvil
#

Please don't randomly post like this

quiet flint
#

User can access all of my database by manipulating date

#

*device date