cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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"))

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.