<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to add a new datetime column to a spark dataFrame from existing timestamp column in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-add-a-new-datetime-column-to-a-spark-dataframe-from/m-p/20744#M14039</link>
    <description>&lt;P&gt;&lt;/P&gt;&lt;P&gt;val df = Seq(("2021-11-05 02:46:47.154410"),("2019-10-05 2:46:47.154410")).toDF("old_column")&lt;/P&gt;&lt;P&gt;display(df)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import org.apache.spark.sql.functions._&lt;/P&gt;&lt;P&gt;val df2 = df.withColumn("new_column", from_unixtime(unix_timestamp(col("old_column"), "yyyy-MM-dd HH:mm:ss.SSSSSS"),"yyyy-MM-dd HH:mm:ss"))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;display(df2)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tested this and this should work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Jun 2021 13:07:59 GMT</pubDate>
    <dc:creator>Srikanth_Gupta_</dc:creator>
    <dc:date>2021-06-25T13:07:59Z</dc:date>
    <item>
      <title>How to add a new datetime column to a spark dataFrame from existing timestamp column</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-add-a-new-datetime-column-to-a-spark-dataframe-from/m-p/20743#M14038</link>
      <description>&lt;P&gt;I have a data frame in Spark that has a column timestamp. I want to add a new column to this data frame that has the DateTime in the below format created from this existing timestamp column.&lt;/P&gt;&lt;P&gt;“YYYY-MM-DD HH:MM:SS”&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 15:07:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-add-a-new-datetime-column-to-a-spark-dataframe-from/m-p/20743#M14038</guid>
      <dc:creator>User16790091296</dc:creator>
      <dc:date>2021-06-24T15:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a new datetime column to a spark dataFrame from existing timestamp column</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-add-a-new-datetime-column-to-a-spark-dataframe-from/m-p/20744#M14039</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;P&gt;val df = Seq(("2021-11-05 02:46:47.154410"),("2019-10-05 2:46:47.154410")).toDF("old_column")&lt;/P&gt;&lt;P&gt;display(df)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import org.apache.spark.sql.functions._&lt;/P&gt;&lt;P&gt;val df2 = df.withColumn("new_column", from_unixtime(unix_timestamp(col("old_column"), "yyyy-MM-dd HH:mm:ss.SSSSSS"),"yyyy-MM-dd HH:mm:ss"))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;display(df2)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tested this and this should work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2021 13:07:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-add-a-new-datetime-column-to-a-spark-dataframe-from/m-p/20744#M14039</guid>
      <dc:creator>Srikanth_Gupta_</dc:creator>
      <dc:date>2021-06-25T13:07:59Z</dc:date>
    </item>
  </channel>
</rss>

