DATE CONVERSION SCALA

Skyflakes

I just want to ask if it's possible to convert a string to date without changing it's format?

 .withColumn("birthdate",when(col("birthday").isNotNull,to_date(col("birthday"),"MM/dd/YYYY")).otherwise(null))

I have a string "01/01/1990" but when I use to_date(col("birthday"),"MM/dd/YYYY"), it becomes 1990-01-01

Is there any way to convert the string to date without changing it's original format or it is only the format for date datatypes?

Thank you in advanced !

Shu

By default spark uses yyyy-MM-dd format for date type.

if you want to have MM/dd/YYYY format as date type then its not possible with spark (results null value).

Example:

Converting MM/dd/YYYY to date type:

scala> spark.sql("select date('01/01/1990') as dt").show()
//+----+
//|  dt|
//+----+
//|null| //result null
//+----+


scala> spark.sql("select date('01/01/1990') as dt").printSchema
//root
 //|-- dt: date (nullable = true)

Converting YYYY-MM-dd to date type:

scala> spark.sql("select date('1990-01-01') as dt").show(false)
//+----------+
//|dt        |
//+----------+
//|1990-01-01| //results data
//+----------+


scala> spark.sql("select date('1990-01-01') as dt").printSchema
//root
// |-- dt: date (nullable = true)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Date conversion to a different locale

分類Dev

Conversion of date formats

分類Dev

PHP String to date conversion

分類Dev

Scala -> Ruby conversion: Confusing output

分類Dev

Sql Server string to date conversion

分類Dev

Notice: Array to string conversion with date

分類Dev

Date conversion and subtraction in shell script

分類Dev

bigInt to date conversion giving errors

分類Dev

Excel Date& Time Conversion

分類Dev

Java String Date conversion issue

分類Dev

spark scala dataframe timestamp conversion sorting?

分類Dev

How does Scala java conversion work?

分類Dev

Conversion of number to date affect the performance in oracle

分類Dev

PHP date() to Excel serial format conversion

分類Dev

Date conversion to specific format using Angular pipes

分類Dev

Default Date to JSON conversion format in Angular app

分類Dev

Java - SimpleDateFormat string to Date to mills conversion

分類Dev

MySQL date conversion(“01/Jan/2015” to “01012015”)

分類Dev

Date time conversion in Javascript from format "/Date(1535515200000)/"

分類Dev

Scala implicit conversion from Array[T] to IndexedSeq[T]

分類Dev

How to convert list to dataframe without type conversion on date

分類Dev

SQL Server Date time conversion giving incorrect result?

分類Dev

T-SQL Procedure not working, issue with varchar to date conversion

分類Dev

oracle to_date conversion showing literal does not match string format

分類Dev

conversion failed when converting date and/or time from character string in xml

分類Dev

SQL Server - Deleting rows between a date range using SQL. Date conversion fails

分類Dev

How to retrieve the month from a date column values in scala dataframe?

分類Dev

Scala Play Forms verify that one date occurs after another

分類Dev

SQL Server - DATE conversion from DATETIME is non-deterministic but only in user-defined function

Related 関連記事

  1. 1

    Date conversion to a different locale

  2. 2

    Conversion of date formats

  3. 3

    PHP String to date conversion

  4. 4

    Scala -> Ruby conversion: Confusing output

  5. 5

    Sql Server string to date conversion

  6. 6

    Notice: Array to string conversion with date

  7. 7

    Date conversion and subtraction in shell script

  8. 8

    bigInt to date conversion giving errors

  9. 9

    Excel Date& Time Conversion

  10. 10

    Java String Date conversion issue

  11. 11

    spark scala dataframe timestamp conversion sorting?

  12. 12

    How does Scala java conversion work?

  13. 13

    Conversion of number to date affect the performance in oracle

  14. 14

    PHP date() to Excel serial format conversion

  15. 15

    Date conversion to specific format using Angular pipes

  16. 16

    Default Date to JSON conversion format in Angular app

  17. 17

    Java - SimpleDateFormat string to Date to mills conversion

  18. 18

    MySQL date conversion(“01/Jan/2015” to “01012015”)

  19. 19

    Date time conversion in Javascript from format "/Date(1535515200000)/"

  20. 20

    Scala implicit conversion from Array[T] to IndexedSeq[T]

  21. 21

    How to convert list to dataframe without type conversion on date

  22. 22

    SQL Server Date time conversion giving incorrect result?

  23. 23

    T-SQL Procedure not working, issue with varchar to date conversion

  24. 24

    oracle to_date conversion showing literal does not match string format

  25. 25

    conversion failed when converting date and/or time from character string in xml

  26. 26

    SQL Server - Deleting rows between a date range using SQL. Date conversion fails

  27. 27

    How to retrieve the month from a date column values in scala dataframe?

  28. 28

    Scala Play Forms verify that one date occurs after another

  29. 29

    SQL Server - DATE conversion from DATETIME is non-deterministic but only in user-defined function

ホットタグ

アーカイブ