The UTC range for 2021 starts at 1609459200 and ends at the exclusive boundary 1640995200. The year has 365 days.

Use the year as a half-open range

WHERE event_time >= 1609459200
  AND event_time <  1640995200

The exclusive upper boundary is safer than “December 31 at 23:59:59.” It works whether the database stores whole seconds, milliseconds, or fractions of a second.

Month starts in UTC

Month start Unix seconds ISO 8601 UTC
January 1 1609459200 2021-01-01T00:00:00Z
February 1 1612137600 2021-02-01T00:00:00Z
March 1 1614556800 2021-03-01T00:00:00Z
April 1 1617235200 2021-04-01T00:00:00Z
May 1 1619827200 2021-05-01T00:00:00Z
June 1 1622505600 2021-06-01T00:00:00Z
July 1 1625097600 2021-07-01T00:00:00Z
August 1 1627776000 2021-08-01T00:00:00Z
September 1 1630454400 2021-09-01T00:00:00Z
October 1 1633046400 2021-10-01T00:00:00Z
November 1 1635724800 2021-11-01T00:00:00Z
December 1 1638316800 2021-12-01T00:00:00Z

Quarter boundaries

  • Q1: 1609459200 (2021-01-01T00:00:00Z)
  • Q2: 1617235200 (2021-04-01T00:00:00Z)
  • Q3: 1625097600 (2021-07-01T00:00:00Z)
  • Q4: 1633046400 (2021-10-01T00:00:00Z)
  • Next year: 1640995200 (2022-01-01T00:00:00Z)

These are UTC values. If the business timezone is not UTC, its local year begins at a different instant; calculate those boundaries in the named location before storing the result.