Σημείωση
Η πρόσβαση σε αυτή τη σελίδα απαιτεί εξουσιοδότηση. Μπορείτε να δοκιμάσετε να συνδεθείτε ή να αλλάξετε καταλόγους.
Η πρόσβαση σε αυτή τη σελίδα απαιτεί εξουσιοδότηση. Μπορείτε να δοκιμάσετε να αλλάξετε καταλόγους.
Gets the difference between the timestamps in the specified units by truncating the fraction part.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.timestamp_add(unit=<unit>, quantity=<quantity>, ts=<ts>)
Parameters
| Parameter | Type | Description |
|---|---|---|
unit |
literal string |
This indicates the units of the difference between the given timestamps. Supported options are (case insensitive): "YEAR", "QUARTER", "MONTH", "WEEK", "DAY", "HOUR", "MINUTE", "SECOND", "MILLISECOND" and "MICROSECOND". |
quantity |
pyspark.sql.Column or str |
The number of units of time that you want to add. |
ts |
pyspark.sql.Column or str |
A timestamp to which you want to add. |
Returns
pyspark.sql.Column: the difference between the timestamps.
Examples
import datetime
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame(
[(datetime.datetime(2016, 3, 11, 9, 0, 7), 2),
(datetime.datetime(2024, 4, 2, 9, 0, 7), 3)], ['ts', 'quantity'])
df.select('*', dbf.timestamp_add('year', 'quantity', 'ts')).show()
df.select('*', dbf.timestamp_add('WEEK', dbf.lit(5), df.ts)).show()
df.select('*', dbf.timestamp_add('day', dbf.lit(-5), 'ts')).show()