0

I have a piece of Spark code that looks like this:

df //existing dataframe
  .withColumn("input_date", lit("20190105"))
  .withColumn("input_date_epoch", unix_timestamp(col("input_date"), "YYYYMMdd"))

Now, when I run a df.describe the data returned shows the input_date_epoch column having all values as 1546128000, which when I run through an epoch converter comes out as 2018-12-30 00:00:00, rather than the expected value of 2019-01-05 00:00:00

Am I doing something wrong here?

1 Answer 1

1

The pattern is wrong, if you want a year with four digits, use yyyy:

spark.range(5)
  .withColumn("input_date", lit("20190105"))
  .withColumn("input_date_epoch", unix_timestamp(col("input_date"), "yyyyMMdd"))

YYYYY actually refers to weekyear, see the documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.