Contact

DAYSINMONTH Function (LibreOffice Calc)

Date & Time Beginner LibreOffice Calc LibreOffice 3.5

The DAYSINMONTH function returns the number of days in the month of a given date. It is essential for calendar logic, scheduling, validation, and building dynamic date workflows.

Verification status: Consult the documentation and examples below. Native application testing has not been documented for this guide. How formula examples are checked

The **DAYSINMONTH** function returns the **number of days in the month** of a given date. It automatically accounts for leap years and works with real dates, serial numbers, and text converted with DATEVALUE. DAYSINMONTH is essential for scheduling, validation, calendar logic, and dynamic date workflows.

What the DAYSINMONTH Function Does

  • Returns the number of days in the month of a given date
  • Automatically handles leap years
  • Works with dates, datetimes, and serial numbers
  • Ideal for validation, scheduling, and calendar calculations

It is designed to be simple, accurate, and essential for month‑based logic.

Syntax

DAYSINMONTH(date_value)

Arguments

  • date_value:
    A date, datetime, or serial number representing a date.

Basic Examples

Days in March 2024

=DAYSINMONTH("2024-03-15")

Returns 31.

Days in February 2024 (leap year)

=DAYSINMONTH("2024-02-01")

Returns 29.

Days in February 2023 (non‑leap year)

=DAYSINMONTH("2023-02-10")

Returns 28.

Using a cell reference

=DAYSINMONTH(A1)

Advanced Examples

Days in the current month

=DAYSINMONTH(TODAY())

Days in next month

=DAYSINMONTH(EDATE(TODAY(); 1))

Days in previous month

=DAYSINMONTH(EDATE(TODAY(); -1))

Days in month from text using DATEVALUE

=DAYSINMONTH(DATEVALUE(A1))

Days in month from imported CSV timestamp

=DAYSINMONTH(DATEVALUE(LEFT(A1;10)))

Days in month from Excel serial date stored as text

=DAYSINMONTH(DATE(1899;12;30)+VALUE(A1))

Determine if a month has 31 days

=DAYSINMONTH(A1)=31

Determine if a date is in February

=MONTH(A1)=2

Determine if a date is in a leap‑year February

=AND(MONTH(A1)=2; DAYSINMONTH(A1)=29)

Build a label like “February has 29 days”

=TEXT(A1;"MMMM") & " has " & DAYSINMONTH(A1) & " days"

Edge Cases and Behavior Details

DAYSINMONTH returns an integer (28–31)

Accepts:

  • Real dates
  • Serial numbers
  • DATEVALUE outputs
  • ISO date strings

Invalid text → Err:502

DAYSINMONTH ignores:

  • Time components
  • Timezones
  • Seconds/milliseconds

DAYSINMONTH of a number < 1 → Err:502

(Serial numbers must represent valid dates)

DAYSINMONTH of an error → error propagates

Leap‑year logic is fully automatic

February returns 29 days when YEAR(date) is a leap year.

Common Errors and Fixes

Err:502 — Invalid argument

Cause:

  • Text not recognized as a date
  • Negative serial numbers
  • Non-numeric values

Fix:

  • Wrap with DATEVALUE
  • Clean text with TRIM or SUBSTITUTE

Wrong month due to locale parsing

Fix:

  • Convert to ISO format before DATEVALUE

Unexpected result from serial numbers

Cause:

  • Imported values represent days since epoch

Fix:

  • Convert with DATE(1899;12;30)+VALUE(A1)

Best Practices

  • Use DAYSINMONTH for validation and scheduling
  • Normalize text dates with DATEVALUE
  • Use DAYSINMONTH with EDATE/EOMONTH for rolling periods
  • Use DAYSINMONTH to detect leap‑year February
  • Use DAYSINMONTH for calendar generation and automation
DAYSINMONTH is your month‑length engine — perfect for scheduling, validation, calendar logic, and any workflow that depends on knowing exactly how many days a month contains.
  • Use EOMONTH to get the last day of a month
  • Use EDATE for month offsets
  • Use YEAR, MONTH, DAY for component extraction
  • Use DATEVALUE for text conversion
  • Use TODAY for dynamic calculations

By mastering DAYSINMONTH and its companion functions, you can build powerful, reliable, and fully dynamic date‑driven workflows in LibreOffice Calc.