Spark SQL - Convert String to Date

Raymond Raymond visibility 20,823 event 2020-10-23 access_time 2 years ago language English

In Spark, function to_date can be used to convert string to date. This function is available since Spark 1.5.0.

Code snippet

SELECT to_date('2020-10-23', 'yyyy-MM-dd');
SELECT to_date('23Oct2020', 'ddMMMyyyy');

Datetime patterns

Refer to the official documentation about all the datetime patterns.

GeratextAD; Anno Domini
yyearyear2020; 20
M/Lmonth-of-yearmonth7; 07; Jul; July
Q/qquarter-of-yearnumber/text3; 03; Q3; 3rd quarter
Eday-of-weektextTue; Tuesday
Faligned day of week in monthnumber(1)3
hclock-hour-of-am-pm (1-12)number(2)12
Khour-of-am-pm (0-11)number(2)0
kclock-hour-of-day (1-24)number(2)0
Hhour-of-day (0-23)number(2)0
Vtime-zone IDzone-idAmerica/Los_Angeles; Z; -08:30
ztime-zone namezone-namePacific Standard Time; PST
Olocalized zone-offsetoffset-OGMT+8; GMT+08:00; UTC-08:00;
Xzone-offset ‘Z’ for zerooffset-XZ; -08; -0830; -08:30; -083015; -08:30:15;
xzone-offsetoffset-x+0000; -08; -0830; -08:30; -083015; -08:30:15;
Zzone-offsetoffset-Z+0000; -0800; -08:00;
escape for textdelimiter 
’‘single quoteliteral
[optional section start  
]optional section end  

More from Kontext
info Last modified by Raymond 2 years ago copyright This page is subject to Site terms.
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts