02-02-2022 08:25 AM
Hi all,
Was wondering if there was any built in function or code that I could utilize to convert a singular week of year integer (i.e. 1 to 52), into a value representing month (i.e. 1-12)?
The assumption is that a week start on a Monday and end on a Sunday.
Thanks!
02-02-2022 11:41 AM
we need old parser as new doesn't support weeks. Than we can map what we need using w - year of year and u - first day of the week:
spark.sql("set spark.sql.legacy.timeParserPolicy=LEGACY")
spark.sql("""
SELECT
extract(
month from to_date("2022-12-1", "y-w-u")
) as month_of_year
""")
02-02-2022 11:41 AM
we need old parser as new doesn't support weeks. Than we can map what we need using w - year of year and u - first day of the week:
spark.sql("set spark.sql.legacy.timeParserPolicy=LEGACY")
spark.sql("""
SELECT
extract(
month from to_date("2022-12-1", "y-w-u")
) as month_of_year
""")
02-06-2022 03:00 AM
Hi @Stanley Tsang , Does @Hubert Dudek 's solution work for you?
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.