---
title: month
description: "month function in PySpark: Extract the month of a given date/timestamp as integer."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/functions/month
---

# month

Extract the month of a given date/timestamp as integer.

For the corresponding Databricks SQL function, see [`month` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/month.md).

## Syntax

```python
from pyspark.sql import functions as dbf

dbf.month(col=<col>)
```

## Parameters

| Parameter | Type                          | Description                              |
| --------- | ----------------------------- | ---------------------------------------- |
| `col`     | `pyspark.sql.Column` or `str` | target date/timestamp column to work on. |

## Returns

`pyspark.sql.Column`: month part of the date/timestamp as integer.

## Examples

```python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08',), ('2024-10-31',)], ['dt'])
df.select("*", dbf.typeof('dt'), dbf.month('dt')).show()
df = spark.createDataFrame([('2015-04-08 13:08:15',), ('2024-10-31 10:09:16',)], ['ts'])
df.select("*", dbf.typeof('ts'), dbf.month('ts')).show()
import datetime
df = spark.createDataFrame([
(datetime.date(2015, 4, 8),),
(datetime.date(2024, 10, 31),)], ['dt'])
df.select("*", dbf.typeof('dt'), dbf.month('dt')).show()
import datetime
df = spark.createDataFrame([
(datetime.datetime(2015, 4, 8, 13, 8, 15),),
(datetime.datetime(2024, 10, 31, 10, 9, 16),)], ['ts'])
df.select("*", dbf.typeof('ts'), dbf.month('ts')).show()
```
