<?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: Convert String to Timestamp in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29058#M20815</link>
    <description>&lt;P&gt;hope you dont mind if i ask you to elaborate further for a shaper understanding? see my basketball court layout at &lt;A href="https://www.recreationtipsy.com/basketball-court/" target="test_blank"&gt;https://www.recreationtipsy.com/basketball-court/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Sep 2019 09:31:20 GMT</pubDate>
    <dc:creator>gideon</dc:creator>
    <dc:date>2019-09-19T09:31:20Z</dc:date>
    <item>
      <title>Convert String to Timestamp</title>
      <link>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29052#M20809</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I have a dataset with one column of string type ('2014/12/31 18:00:36'). How can I convert it to timastamp type with PySpark?&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Nov 2017 18:58:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29052#M20809</guid>
      <dc:creator>vaio</dc:creator>
      <dc:date>2017-11-18T18:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: Convert String to Timestamp</title>
      <link>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29053#M20810</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I am trying to do it in this way, however, the result is null.&lt;/P&gt;
&lt;P&gt;df2 = df.select(col('starting_timestamp'), df.starting_timestamp.cast('timestamp').alias('time'))&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;+-------------------+----+
| starting_timestamp|time|
+-------------------+----+
|2015/01/01 03:00:36|null|
|2015/01/01 03:01:06|null|
|2015/01/01 03:01:12|null|
|2015/01/01 03:01:20|null|
|2015/01/01 03:01:27|null|
+-------------------+----+
only showing top 5 rows&lt;/CODE&gt;&lt;/PRE&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 21:26:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29053#M20810</guid>
      <dc:creator>vaio</dc:creator>
      <dc:date>2017-11-19T21:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: Convert String to Timestamp</title>
      <link>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29054#M20811</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I found the solution. It is as follows:&lt;/P&gt;
&lt;P&gt;df2 = df.select('ID', 'starting_timestamp', unix_timestamp('starting_timestamp', "yyyy/MM/dd HH:mm:ss") .cast(TimestampType()).alias("timestamp"))&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 21:42:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29054#M20811</guid>
      <dc:creator>vaio</dc:creator>
      <dc:date>2017-11-19T21:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Convert String to Timestamp</title>
      <link>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29055#M20812</link>
      <description>&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Iam facing the same problem with the Pyspark where iam getting null after change to timestamp.The data set similar to above with some additional column&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;df2 = df.select('Customer', 'Transaction_Timestamp','Transaction_Base_Point_Value', unix_timestamp('Transaction_Timestamp', "yyyy/MM/dd HH:mm:ss") .cast(TimestampType()).alias("timestamp"))
|-- Customer: string (nullable = true)
 |-- Transaction_Timestamp: string (nullable = true)
 |-- Transaction_Base_Point_Value: integer (nullable = true)
 |-- timestamp: timestamp (nullable = true)
&amp;nbsp;
But output of timestamp column return null&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 07:21:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29055#M20812</guid>
      <dc:creator>hariumesh</dc:creator>
      <dc:date>2019-03-25T07:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Convert String to Timestamp</title>
      <link>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29056#M20813</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;It is strange that it returns null. It works fine for me in pyspark as well. Could you please compare the code? Also try displaying the earlier dataframe. pls make sure that the values in original dataframe are displaying properly and are in appropriate datatypes (StringType).&lt;/P&gt;
&lt;P&gt;```&lt;/P&gt;from pyspark.sql.functions import unix_timestamp, col
&lt;P&gt;&lt;/P&gt; 
&lt;P&gt;from pyspark.sql.types import TimestampType&lt;/P&gt; 
&lt;P&gt;from pyspark.sql.types import StringType&lt;/P&gt; 
&lt;P&gt;df = spark.createDataFrame(["2015/01/01 03:00:36"], StringType()).toDF("ts_string")&lt;/P&gt; 
&lt;P&gt;df1 = df.select(unix_timestamp(df.ts_string, 'yyyy/MM/dd HH:mm:ss').cast(TimestampType()).alias("timestamp"))&lt;/P&gt; 
&lt;P&gt;df1.show()&lt;/P&gt;
&lt;P&gt;```&lt;/P&gt;
&lt;P&gt;If it still doesn't resolve, please share the full code, including how you are creating the original dataframe. Please let us know how it goes.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 12:29:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29056#M20813</guid>
      <dc:creator>mathan_pillai</dc:creator>
      <dc:date>2019-03-26T12:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert String to Timestamp</title>
      <link>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29057#M20814</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hi &lt;/P&gt;
&lt;P&gt;i have Spark 1.6.0 on Cloudera 5.13.0 &lt;/P&gt;
&lt;P&gt;i have the same problem and this is my full code , please help me &lt;/P&gt;
&lt;P&gt;this is the format of my row : 25/Jan/2016:21:26:37 +0100&lt;/P&gt;
&lt;P&gt;from pyspark.sql import HiveContext&lt;/P&gt;
&lt;P&gt;from pyspark.sql.functions import unix_timestamp, col&lt;/P&gt;
&lt;P&gt; from pyspark.sql.types import TimestampType&lt;/P&gt;
&lt;P&gt;from pyspark.sql.types import StringType&lt;/P&gt;
&lt;P&gt;SQLContext = HiveContext(sc)&lt;/P&gt;
&lt;P&gt;df=sqlContext.sql("select * from test.test")&lt;/P&gt;
&lt;P&gt;df1 = df.select(unix_timestamp(df.date_hour, 'yyyy/MM/dd:HH:mm:ss').cast(TimestampType()).alias("timestamp"))&lt;/P&gt;
&lt;P&gt;df1.show()&lt;/P&gt;
&lt;P&gt;it still null&lt;/P&gt; 
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 13:49:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29057#M20814</guid>
      <dc:creator>Doha</dc:creator>
      <dc:date>2019-05-08T13:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Convert String to Timestamp</title>
      <link>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29058#M20815</link>
      <description>&lt;P&gt;hope you dont mind if i ask you to elaborate further for a shaper understanding? see my basketball court layout at &lt;A href="https://www.recreationtipsy.com/basketball-court/" target="test_blank"&gt;https://www.recreationtipsy.com/basketball-court/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2019 09:31:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/convert-string-to-timestamp/m-p/29058#M20815</guid>
      <dc:creator>gideon</dc:creator>
      <dc:date>2019-09-19T09:31:20Z</dc:date>
    </item>
  </channel>
</rss>

