Products

MONTH function

PRO BASIC

In Jspreadsheet Formulas Pro, the MONTH function is used to retrieve the month from a given date, which is represented by a serial number. This function will provide an integer value corresponding to the month, which ranges from 1 to 12. For instance, if the date is in January, the output will be 1, and if it's in December, the output will be 12. This function is very useful when you need to perform operations based on the month of a specific date.

Documentation

Returns the month of a date represented by a serial number. The month is given as an integer, ranging from 1 (January) to 12 (December).

Category

Date and time

Syntax

MONTH(serial_number)

Parameter Description
serial_number The date for which you want to determine the month. Jspreadsheet stores dates as sequential serial numbers so they can be used in calculations.

Behavior

The MONTH function is used to obtain the month portion of a specific date. This function expects a single argument, which is the date from which the month is to be extracted.

  • If the cell is empty, the MONTH function will return a #VALUE! error.
  • If the cell contains text that cannot be interpreted as a date, the MONTH function will return a #VALUE! error.
  • If the cell contains a boolean, the MONTH function will treat it as a date starting from December 30, 1899, with TRUE being 1 (December 31, 1899) and FALSE being 0 (December 30, 1899), and return the corresponding month.
  • If the cell contains an error, the MONTH function will propagate that error.
  • The MONTH function always returns an integer between 1 and 12, inclusive.

Common Errors

Error Description
#VALUE! The function returns this error when the argument to the MONTH function cannot be interpreted as a date. This includes empty cells and text that does not represent a date.
#NUM! This error is returned if the supplied date argument is outside Jspreadsheet’s supported date range.
#REF! This error is returned when the referenced cell is invalid.

Best practices

  • Always ensure that the argument to the MONTH function is a valid date or a cell reference to a date.
  • Be careful when using boolean values as arguments to the MONTH function. The results may not be what you expect.
  • To avoid confusion, it is recommended to format the result of the MONTH function to display as a month name rather than a number.

Usage

A few examples using the MONTH function.

MONTH(DATE(2022,3,15)) // returns 3  
MONTH("2023-05-25") // returns 5  
MONTH(TODAY()) // returns the current month number  
MONTH(A1) // if A1 contains 2023-12-10, returns 12  

Interactive Spreadsheet Demo

<html>
<script src="https://jspreadsheet.com/v11/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v11/jspreadsheet.css" type="text/css" />

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/formula-pro/dist/index.min.js"></script>

<div id="spreadsheet"></div>

<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('ZTA2YzQ3OWQzMzM2OTRiNTUwYzBkNDBiMzgxYjE5MGM4MzZlY2U0NzE3OThkZGJjZTZhYTZmMmM3MTc5ZDI2ZjU1YTZiZjgxNDM2NjljNzFiNjNiM2QzYmUxYWFjYWMxZDgyOTVkYTkyNjBiNDhjY2ZkNzhhOGFjYzZjMjJiYjgsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01ETXdOakV6TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');

// Set the extensions
jspreadsheet.setExtensions({ formula });

// Create a new spreadsheet
jspreadsheet(document.getElementById('spreadsheet'), {
  worksheets: [{
    data: [
    [
        "Date",
        "Month"
    ],
    [
        "2023-01-15",
        "=MONTH(A2)"
    ],
    [
        "2023-06-22",
        "=MONTH(A3)"
    ],
    [
        "2023-12-05",
        "=MONTH(A4)"
    ]
]
  }]
});
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";

// Set license
jspreadsheet.setLicense('ZTA2YzQ3OWQzMzM2OTRiNTUwYzBkNDBiMzgxYjE5MGM4MzZlY2U0NzE3OThkZGJjZTZhYTZmMmM3MTc5ZDI2ZjU1YTZiZjgxNDM2NjljNzFiNjNiM2QzYmUxYWFjYWMxZDgyOTVkYTkyNjBiNDhjY2ZkNzhhOGFjYzZjMjJiYjgsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01ETXdOakV6TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');

// Set the extensions
jspreadsheet.setExtensions({ formula });

export default function App() {
    // Spreadsheet array of worksheets
    const spreadsheet = useRef();

    // Worksheet data
    const data = [
    [
        "Date",
        "Month"
    ],
    [
        "2023-01-15",
        "=MONTH(A2)"
    ],
    [
        "2023-06-22",
        "=MONTH(A3)"
    ],
    [
        "2023-12-05",
        "=MONTH(A4)"
    ]
];

    // Render component
    return (
        <Spreadsheet ref={spreadsheet}>
            <Worksheet data={data} />
        </Spreadsheet>
    );
}
<template>
    <Spreadsheet ref="spreadsheet">
        <Worksheet :data="data" />
    </Spreadsheet>
</template>

<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
import formula from "@jspreadsheet/formula-pro";

// Set license
jspreadsheet.setLicense('ZTA2YzQ3OWQzMzM2OTRiNTUwYzBkNDBiMzgxYjE5MGM4MzZlY2U0NzE3OThkZGJjZTZhYTZmMmM3MTc5ZDI2ZjU1YTZiZjgxNDM2NjljNzFiNjNiM2QzYmUxYWFjYWMxZDgyOTVkYTkyNjBiNDhjY2ZkNzhhOGFjYzZjMjJiYjgsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01ETXdOakV6TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');

// Set the extensions
jspreadsheet.setExtensions({ formula });

export default {
    components: {
        Spreadsheet,
        Worksheet,
    },
    data() {
        // Worksheet data
        const data = [
    [
        "Date",
        "Month"
    ],
    [
        "2023-01-15",
        "=MONTH(A2)"
    ],
    [
        "2023-06-22",
        "=MONTH(A3)"
    ],
    [
        "2023-12-05",
        "=MONTH(A4)"
    ]
]

        return {
            data
        };
    }
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import * as formula from "@jspreadsheet/formula-pro";

// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('ZTA2YzQ3OWQzMzM2OTRiNTUwYzBkNDBiMzgxYjE5MGM4MzZlY2U0NzE3OThkZGJjZTZhYTZmMmM3MTc5ZDI2ZjU1YTZiZjgxNDM2NjljNzFiNjNiM2QzYmUxYWFjYWMxZDgyOTVkYTkyNjBiNDhjY2ZkNzhhOGFjYzZjMjJiYjgsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01ETXdOakV6TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');

// Set the extensions
jspreadsheet.setExtensions({ formula });

@Component({
    standalone: true,
    selector: "app-root",
    template: `<div #spreadsheet></div>`
})
export class AppComponent {
    @ViewChild("spreadsheet") spreadsheet: ElementRef;
    // Worksheets
    worksheets: jspreadsheet.worksheetInstance[];

    // Create a new data grid
    ngAfterViewInit() {
        // Create spreadsheet
        this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
            worksheets: [{
                data: [
    [
        "Date",
        "Month"
    ],
    [
        "2023-01-15",
        "=MONTH(A2)"
    ],
    [
        "2023-06-22",
        "=MONTH(A3)"
    ],
    [
        "2023-12-05",
        "=MONTH(A4)"
    ]
]
            }]
        });
    }
}