SQL week format issue its not showing result as 01(ww)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2021 08:45 AM
Hi Folks,
I've requirement to show the week number as ww format. Please see the below code
select weekofyear(date_add(to_date(current_date, 'yyyyMMdd'), +35)). also plz refre the screen shot for result.
- Labels:
-
Current Date
-
Databricks SQL
-
Format
-
SQL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2021 09:36 AM
date_add id adding days. Today is 1st December and +35 days it gives 5th January which is first week of 2022 so result 1 is correct as returned by weekofyear function.
If you need just add leading zero the best way is to format it in visualization tool like / BI.
If you need leading zero in spark it will be have to be the string:
SELECT lpad(weekofyear(date_add(current_date, 35)), 2, '0')It could be nice that date object is just format (date_format) as week number WW/ww but in spark is not included in date formatting: https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html
My blog: https://databrickster.medium.com/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2021 10:33 AM
You can use lpad() to achieve the 'ww' format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2026 06:22 AM
What Is Papa’s Freezeria?
Papa’s Freezeria is part of the famous Papa Louie game series, where players take on the role of restaurant employees running one of Papa Louie’s many eateries. http://papasfreezeria.online/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
"I've been exploring different communities lately, and honestly, connecting with people who share your interests makes all the difference. Whether it's diving deep into data engineering discussions or just having random conversations on platforms like Omegle, there's something fun about learning from strangers. You never know who you'll meet or what cool insights they'll share about tackling real-world engineering challenges!"