QuestionQ118

VerifiedUsing Spark SQL

Which of the following code blocks returns a DataFrame containing an openDateString column, a string representation in Java’s SimpleDateFormat?

Note that the openDate column is an integer and represents a date in UNIX epoch format—the number of seconds since midnight on January 1st, 1970.

An example of Java's SimpleDateFormat is "Sunday, Dec 4, 2008 1:05 pm".

A sample of storesDF is displayed below:

Question Image

Explanation

from_unixtime converts a column of Unix epoch seconds to a formatted string. Applying it with withColumn and the pattern EEEE, MMM d, yyyy h:mm a creates the required formatted date-string column. The function accepts the epoch-seconds value and an optional format string; TimestampType is not an argument to this function.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!