current_date, to_date & to_timestamp
Dates usually arrive as strings. to_date parses a string into a real DateType (and to_timestamp into a TimestampType) so you can do arithmetic and comparisons on it. current_date and current_timestamp give you today/now.
def current_date(): Column def current_timestamp(): Column def to_date(e: Column): Column // parses ISO yyyy-MM-dd def to_date(e: Column, fmt: String): Column // custom pattern def to_timestamp(e: Column, fmt: String): Column
import org.apache.spark.sql.functions.{to_date, current_date}
people.select(
$"name",
to_date($"signup_date").as("signup"),
current_date().as("today")
).show(3, false)to_date($"d", "dd/MM/yyyy"). On a bad or mismatched value, Spark returns null rather than erroring — so always check for nulls after parsing untrusted data. A DateType has no time; use to_timestamp when you need the clock.