btava001
btava001

Reputation: 131

Validating Today's Day of Week

I am using the query below to check if today is Friday but it keeps returning False. Can someone help?

select case when to_char(now(), 'Day') = 'Friday' then 'True' else 'False'
end

Upvotes: 0

Views: 24

Answers (2)

jjanes
jjanes

Reputation: 44137

The output of to_char is padded to the length of the longest day name.

select trim(to_char(now(), 'Day'))='Friday';

Upvotes: 1

Jeremy
Jeremy

Reputation: 6723

How about grabbing the day of the week in integer form instead:

SELECT case when extract('dow' from now()) = 5 THEN true else false end;

0 is Sunday, which makes 5 Friday.

Upvotes: 1

Related Questions