Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

636
Views
How many payments happened on Monday from payment _date column? The below code giving me zero count
SELECT COUNT(*)
FROM payment
WHERE(TO_CHAR(payment_date, 'Day')) = 'Monday'
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

TO_CHAR(payment_date, 'Day') returns a string padded with spaces ('Monday ').

To suppress the spaces, use the FM modifier ("fill mode")

SELECT COUNT(*)
FROM payment
WHERE (TO_CHAR(payment_date, 'FMDay')) = 'Monday'

alternatively be explicit and use trim()

SELECT COUNT(*)
FROM payment
WHERE (trim(TO_CHAR(payment_date, 'Day'))) = 'Monday'

However, I would recommend to not use locale specific values (on my computer the above would always return 0 as I have a different language setting).

Using numbers e.g. with extract(isodow from ..) is much more reliable.

over 4 years ago · Santiago Trujillo Report

0

Use dow(day of week).
The day of the week (0 - 6; Sunday is 0) (for timestamp values only)

SELECT COUNT(*)
FROM payment
WHERE EXTRACT(DOW FROM payment_date)= 1;

For more details on the dow check out the documentation.

over 4 years ago · Santiago Trujillo Report

0

SELECT COUNT(*) AS day_of_payment 
FROM payment
WHERE TO_CHAR (payment_date,'DAY') = 'MONDAY   '

Considering that "blank padded to 9 characters", which means instead of returning 'Monday' it returns 'Monday ' with extra spaces to fill up at least 9 spaces.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!