Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Converte una data/timestamp/stringa in un valore di stringa nel formato specificato dal formato di data specificato dal secondo argomento.
Un modello può essere ad esempio dd.MM.yyyy e potrebbe restituire una stringa come '18.03.1993'. È possibile usare tutte le lettere di motivo datetime .
Annotazioni
Quando possibile, usare funzioni specializzate come year.
Per la funzione SQL di Databricks corrispondente, vedere date_format funzione.
Sintassi
from pyspark.databricks.sql import functions as dbf
dbf.date_format(date=<date>, format=<format>)
Parametri
| Parametro | TIPO | Description |
|---|---|---|
date |
pyspark.sql.Column o str |
colonna di input di valori da formattare. |
format |
literal string |
format da utilizzare per rappresentare i valori datetime. |
Restituzioni
pyspark.sql.Column: valore stringa che rappresenta datetime formattato.
Esempi
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08',), ('2024-10-31',)], ['dt'])
df.select("*", dbf.typeof('dt'), dbf.date_format('dt', 'MM/dd/yyyy')).show()
df = spark.createDataFrame([('2015-04-08 13:08:15',), ('2024-10-31 10:09:16',)], ['ts'])
df.select("*", dbf.typeof('ts'), dbf.date_format('ts', 'yy=MM=dd HH=mm=ss')).show()
import datetime
df = spark.createDataFrame([
(datetime.date(2015, 4, 8),),
(datetime.date(2024, 10, 31),)], ['dt'])
df.select("*", dbf.typeof('dt'), dbf.date_format('dt', 'yy--MM--dd')).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.date_format('ts', 'yy=MM=dd HH=mm=ss')).show()