cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert Data Chr Strings to Date Strings

Jeff1
Contributor II

Databricks Community

New to Databricks and work in R code. I have a data from with a date field that is a chr string and need to convert to a date field. Tried the standard as.Date(x, format = "%Y-%m-%d") , then tried the dplyr::mutate function and that errored out to. So how does one convert chr date strings to a Date string.

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

you can use universal sql syntax with R dataframes

df <- read.df(path = "/tmp/df.avro", source = "com.databricks.spark.avro")
createOrReplaceTempView(dfView, "df")
species <- sql("SELECT TO_DATE(string_date, 'dd/MM/yy') FROM dfView")

View solution in original post

3 REPLIES 3

Hubert-Dudek
Esteemed Contributor III

you can use universal sql syntax with R dataframes

df <- read.df(path = "/tmp/df.avro", source = "com.databricks.spark.avro")
createOrReplaceTempView(dfView, "df")
species <- sql("SELECT TO_DATE(string_date, 'dd/MM/yy') FROM dfView")

Well that was certainly helpful - thank you

Jeff1
Contributor II

Based upon the initial response I went with:

my_data.frame <- my_data.frame %>%

mutate(date = to_date(data.frame_variable, "yyyy-mm-dd"))

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group