https://supabase.com/ logo
#sql
Title
# sql
s

stibbs

09/14/2021, 12:16 PM
I want to return all values from a table only if the value in a date column is in the future. I think the simplest way to do this is to get a value for what
now
is, like below. My question: is there a built-in way of doing
now
in PSQL?
Copy code
ts
const now = new Date().getTime();

export const listPosts = async (): Promise<PostgrestResponse<PostTable>> => {
  return supabase
    .from<PostTable>('posts')
    .select('*')
    .gt('expires_at', now)
};
s

silentworks

09/14/2021, 12:31 PM
NOW()
s

stibbs

09/14/2021, 12:39 PM
and i can call that from my js??
Oh wow you totally can
Copy code
ts
export const listPosts = async (): Promise<PostgrestResponse<PostTable>> => {
  return supabase
    .from<PostTable>('posts')
    .select('*')
    .gt('expires_at', 'now()')
};
Thanks 🙂
This is what happens when you try to code at 11pm after a long day 😅
s

Steve

09/24/2021, 12:44 AM
@User You can even do
.gt('expires_at', 'yesterday')
or
.gt('expires_at', 'tomorrow')
🙂 Those are special values in PostgreSQL, that's why they work(also they don't need parens)