How to convert a dynamic string to a date

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

Answers (1)

S-Man
S-Man

Reputation: 23686

You can use make_date() for this:

demo:db<>fiddle

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

Related Questions