Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Extract the day of the month of a given date/timestamp as integer.
For the corresponding Databricks SQL function, see dayofmonth function.
Syntax
from pyspark.sql import functions as dbf
dbf.dayofmonth(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
target date/timestamp column to work on. See Also -------- :meth:pyspark.sql.functions.day :meth:pyspark.sql.functions.dayofyear :meth:pyspark.sql.functions.dayofweek :meth:pyspark.sql.functions.weekofyear |
Returns
pyspark.sql.Column: day of the month for given date/timestamp as integer.
Examples
from pyspark.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08',), ('2024-10-31',)], ['dt'])
df.select("*", dbf.typeof('dt'), dbf.dayofmonth('dt')).show()
df = spark.createDataFrame([('2015-04-08 13:08:15',), ('2024-10-31 10:09:16',)], ['ts'])
df.select("*", dbf.typeof('ts'), dbf.dayofmonth('ts')).show()
import datetime
df = spark.createDataFrame([
(datetime.date(2015, 4, 8),),
(datetime.date(2024, 10, 31),)], ['dt'])
df.select("*", dbf.typeof('dt'), dbf.dayofmonth('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.dayofmonth('ts')).show()