Re: Something like 'to_days' in postgresql? Help with a MySQL - Mailing list pgsql-novice

From Sai Hertz And Control Systems
Subject Re: Something like 'to_days' in postgresql? Help with a MySQL
Date
Msg-id 3FD84C18.9030503@sancharnet.in
Whole thread Raw
In response to Something like 'to_days' in postgresql? Help with a MySQL migration...  ("Alan T. Miller" <amiller@hollywood101.com>)
List pgsql-novice
Dear Alan T. Miller  ,

>I am migrating an application over from mysql to postgresql and am a little
>confused on how to write the following query in PostgreSQL.
>
Migrating to PostgreSQL thats a wise mans act  :-)

>which is a timestamp. In MySQL the query goes as follows...
>
>SELECT COUNT(*) AS total
>FROM orders
>WHERE id = 'id'
>AND TO_DAYS(NOW()) - TO_DAYS(created) <= 90
>
>
Yes , it can be done this is how you will do it :
select
count(*) as total
from  orders
where id = 'id '    <------- For a single id
AND ( age(current_timestamp,created) <= cast('90 days' as interval)) ;
------------------
For Multiple ids do:
-------------------
select
count(*) as total ,
orders.id as Order_No
from  orders
where id = 'orders.id '    <------- For a multiple id
AND ( age(current_timestamp,created) <= cast('90 days' as interval))
group by orders.id;

Tell me if this works plz,

Regards,
V Kashyap

pgsql-novice by date:

Previous
From: Oliver Elphick
Date:
Subject: Re: Something like 'to_days' in postgresql? Help with a
Next
From: "Manu M P"
Date:
Subject: List Data bases and users