diff --git a/pypistats/cli.py b/pypistats/cli.py
index 092f9b7..8eb62cd 100644
--- a/pypistats/cli.py
+++ b/pypistats/cli.py
@@ -243,7 +243,7 @@ def _month(yyyy_mm):
     """Helper to return start_date and end_date of a month as yyyy-mm-dd"""
     year, month = map(int, yyyy_mm.split("-"))
     first = date(year, month, 1)
-    last = date(year, month + 1, 1) - relativedelta(days=1)
+    last = first + relativedelta(months=1) - relativedelta(days=1)
     return str(first), str(last)
 
 

ValueError: month must be in 1..12
```console
$ pypistats python_minor pylast -m 2018-11
| category | percent | downloads |
|----------|--------:|----------:|
|      2.7 |  48.62% |     2,307 |
|      3.6 |  31.63% |     1,501 |
| null     |   7.31% |       347 |
|      3.7 |   6.91% |       328 |
|      3.5 |   4.85% |       230 |
|      3.4 |   0.59% |        28 |
|      3.3 |   0.08% |         4 |
| Total    |         |     4,745 |

$ pypistats python_minor pylast -m 2018-12
Traceback (most recent call last):
  File "/usr/local/bin/pypistats", line 11, in <module>
    load_entry_point('pypistats', 'console_scripts', 'pypistats')()
  File "/Users/hugo/github/pypistats/pypistats/cli.py", line 266, in main
    args.start_date, args.end_date = _month(args.month)
  File "/Users/hugo/github/pypistats/pypistats/cli.py", line 246, in _month
    last = date(year, month + 1, 1) - relativedelta(days=1)
ValueError: month must be in 1..12

$ pypistats python_minor pylast -m 2017-12
Traceback (most recent call last):
  File "/usr/local/bin/pypistats", line 11, in <module>
    load_entry_point('pypistats', 'console_scripts', 'pypistats')()
  File "/Users/hugo/github/pypistats/pypistats/cli.py", line 266, in main
    args.start_date, args.end_date = _month(args.month)
  File "/Users/hugo/github/pypistats/pypistats/cli.py", line 246, in _month
    last = date(year, month + 1, 1) - relativedelta(days=1)
ValueError: month must be in 1..12
```
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 22308f6..f486b7c 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -28,6 +28,17 @@ class TestCli(unittest.TestCase):
         self.assertEqual(first, "2018-07-01")
         self.assertEqual(last, "2018-07-31")
 
+    def test__month_12(self):
+        # Arrange
+        yyyy_mm = "2018-12"
+
+        # Act
+        first, last = cli._month(yyyy_mm)
+
+        # Assert
+        self.assertEqual(first, "2018-12-01")
+        self.assertEqual(last, "2018-12-31")
+
     @freeze_time("2018-09-25")
     def test__last_month(self):
         # Arrange

pip install -e .[dev]
parse_log_pytest
requirements.txt
numpy>=1.16.0 pandas>=1.0.0 freezegun pytest
apt-get update apt-get install -y gcc
3.9
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
appdirs==1.4.4
certifi==2025.1.31
chardet==5.2.0
charset-normalizer==3.4.1
DataProperty==1.1.0
exceptiongroup==1.2.2
freezegun==1.5.1
idna==3.10
iniconfig==2.1.0
mbstrdecoder==1.1.4
numpy==2.0.2
packaging==24.2
pandas==2.2.3
pathvalidate==3.2.3
pluggy==1.5.0
-e git+https://github.com/hugovk/pypistats.git@f6a9e33aaf41d1b08f6490febe1f542c1e093271#egg=pypistats
pytablewriter==1.2.1
pytest==8.3.5
python-dateutil==2.9.0.post0
python-slugify==8.0.4
pytz==2025.2
requests==2.32.3
six==1.17.0
tabledata==1.3.4
tcolorpy==0.1.7
text-unidecode==1.3
tomli==2.2.1
typepy==1.3.4
tzdata==2025.2
urllib3==2.3.0

name: pypistats
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - appdirs==1.4.4
      - certifi==2025.1.31
      - chardet==5.2.0
      - charset-normalizer==3.4.1
      - dataproperty==1.1.0
      - exceptiongroup==1.2.2
      - freezegun==1.5.1
      - idna==3.10
      - iniconfig==2.1.0
      - mbstrdecoder==1.1.4
      - numpy==2.0.2
      - packaging==24.2
      - pandas==2.2.3
      - pathvalidate==3.2.3
      - pluggy==1.5.0
      - pypistats==0.4.0.dev0
      - pytablewriter==1.2.1
      - pytest==8.3.5
      - python-dateutil==2.9.0.post0
      - python-slugify==8.0.4
      - pytz==2025.2
      - requests==2.32.3
      - six==1.17.0
      - tabledata==1.3.4
      - tcolorpy==0.1.7
      - text-unidecode==1.3
      - tomli==2.2.1
      - typepy==1.3.4
      - tzdata==2025.2
      - urllib3==2.3.0
prefix: /opt/conda/envs/pypistats

tests/test_cli.py::TestCli::test__month_12
tests/test_cli.py::TestCli::test__define_format_default tests/test_cli.py::TestCli::test__define_format_json tests/test_cli.py::TestCli::test__define_format_json_flag tests/test_cli.py::TestCli::test__define_format_markdown tests/test_cli.py::TestCli::test__last_month tests/test_cli.py::TestCli::test__month tests/test_cli.py::TestCli::test__valid_yyyy_mm tests/test_cli.py::TestCli::test__valid_yyyy_mm_dd tests/test_cli.py::TestCli::test__valid_yyyy_mm_dd_invalid tests/test_cli.py::TestCli::test__valid_yyyy_mm_dd_invalid2 tests/test_cli.py::TestCli::test__valid_yyyy_mm_invalid tests/test_cli.py::TestCli::test__valid_yyyy_mm_invalid2
pypistats/cli.py
pypistats/cli.py