Reputation: 194
How do I convert a dynamic string to a date in PostgreSQL, I have tried the below?
select Extract(year from CURRENT_DATE)||'-04'||'-01'
select *
from table a
where a.timestamp::date=Extract(year from CURRENT_DATE)||'-04'||'-01'
Upvotes: 1
Views: 100
Reputation: 23686
You can use make_date()
for this:
SELECT
make_date(
extract(year from current_date)::int,
4,
1
)
Of course, you can use this in the WHERE
clause, as well:
WHERE make_date(extract(year from current_date)::int, 4, 1) = ...
Upvotes: 2