How can I get the number of days passed in the current quarter?
For example, if today is 1/2/2021, it will return 2.
If today is 2/5, it will return 36.
If today is 4/2, it will return 2.
How can I get the number of days passed in the current quarter?
For example, if today is 1/2/2021, it will return 2.
If today is 2/5, it will return 36.
If today is 4/2, it will return 2.
Copyright © 2021 Jogjafile Inc.
Use
date_trunc()to get the start of the quarter and subtract dates:+ 1to fix off-by-one error as you clearly want to include the current day as "passed".Always use unambiguous ISO 8601 date format (
YYYY-MM-DD-2021-02-05), which is the default in Postgres and always unambiguous, or you depend on the currentdatestylesetting (and may be in for surprises). Also avoids misunderstandings general communication.Related: