Main Content

calendar

Calendar for specified month

Description

calendar displays a calendar for the current month in a traditional format. The weeks run from Sunday to Saturday, with Sunday as the first column. The display format includes a header that shows the month, year, and abbreviated names for the days of the week.

example

calendar(y,m) displays a calendar for the specified month m in the year y.

example

calendar(d) displays a calendar for the month associated with d, where d is a datetime value or a text timestamp that specifies a year, month, and day.

example

c = calendar returns a calendar for the current month as a 6-by-7 numeric matrix. The matrix has no header.

example

c = calendar(___) returns a calendar for the specified month as a 6-by-7 numeric matrix.

Examples

collapse all

Display a calendar for the current month. The display format includes a header with the month name, year, and days of the week.

calendar
                   Jul 2024
     S     M    Tu     W    Th     F     S
     0     1     2     3     4     5     6
     7     8     9    10    11    12    13
    14    15    16    17    18    19    20
    21    22    23    24    25    26    27
    28    29    30    31     0     0     0
     0     0     0     0     0     0     0

Return the calendar as a numeric matrix. The matrix has no header.

c = calendar
c = 6×7

     0     1     2     3     4     5     6
     7     8     9    10    11    12    13
    14    15    16    17    18    19    20
    21    22    23    24    25    26    27
    28    29    30    31     0     0     0
     0     0     0     0     0     0     0

Display a calendar for December 1999.

calendar(1999,12)
                   Dec 1999
     S     M    Tu     W    Th     F     S
     0     0     0     1     2     3     4
     5     6     7     8     9    10    11
    12    13    14    15    16    17    18
    19    20    21    22    23    24    25
    26    27    28    29    30    31     0
     0     0     0     0     0     0     0

Create a datetime value. Then display a calendar for the month and year specified by that datetime value.

d = datetime("now")
d = datetime
   20-Jul-2024 14:04:23

calendar(d)
                   Jul 2024
     S     M    Tu     W    Th     F     S
     0     1     2     3     4     5     6
     7     8     9    10    11    12    13
    14    15    16    17    18    19    20
    21    22    23    24    25    26    27
    28    29    30    31     0     0     0
     0     0     0     0     0     0     0

You can also specify a text timestamp as the input argument. Display a calendar for January 2022, the month and year specified by "2022-01-01".

d = "2022-01-01"
d = 
"2022-01-01"
calendar(d)
                   Jan 2022
     S     M    Tu     W    Th     F     S
     0     0     0     0     0     0     1
     2     3     4     5     6     7     8
     9    10    11    12    13    14    15
    16    17    18    19    20    21    22
    23    24    25    26    27    28    29
    30    31     0     0     0     0     0

Input Arguments

collapse all

Year number, specified as a nonnegative integer.

Month number, specified as a positive integer between 1 and 12. The month numbers correspond to the months listed in the table.

Month Number

Month Name

1

January

2

February

3

March

4

April

5

May

6

June

7

July

8

August

9

September

10

October

11

November

12

December

Month and year, specified as a datetime scalar or text timestamp whose format includes a year, month, and day. The hour, minute, and second components are ignored.

To support existing code, calendar also accepts serial date numbers as inputs, but they are not recommended. For more information, see Version History.

Data Types: datetime | string | char

Limitations

  • MATLAB® Online™ determines the current month from Coordinated Universal Time (UTC) rather than from local time.

Version History

Introduced before R2006a

expand all