Skip to main content
Solved

Lobby: Extracted Month/Day not Sorting Correctly


Forum|alt.badge.img+10
  • Sidekick (Customer)
  • 119 replies

We have a lobby by week that is not sorting the MM/DD date correctly since it treats it as text.

Can we:

1.) change it to a Date (didn’t work in the DataSource) so it sorts/orders correctly.

2.) Add a leading zero to single-digit months and days.

 

 

Best answer by EntShehaM

question is not quite clear though, is it related to date and month format fixing below queries may help you.

SELECT to_number(to_char(SYSDATE, 'W')) weeks FROM dual; --to get the current week of the month

SELECT to_number(to_char(SYSDATE, 'D')) days FROM dual; --to get the current day of the week

SELECT to_number(to_char(SYSDATE, 'DD')) to_day FROM dual; --to get the current date of the month

SELECT to_number(to_char(SYSDATE, 'MM')) to_month FROM dual; --to get the current month

SELECT to_char(SYSDATE, 'MM/DD') DD_MM FROM dual; --to get the current month/date 

hope above will helpful for your findings..

View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

5 replies

EntShehaM
Hero (Partner)
Forum|alt.badge.img+5
  • Hero (Partner)
  • 30 replies
  • Answer
  • April 13, 2021

question is not quite clear though, is it related to date and month format fixing below queries may help you.

SELECT to_number(to_char(SYSDATE, 'W')) weeks FROM dual; --to get the current week of the month

SELECT to_number(to_char(SYSDATE, 'D')) days FROM dual; --to get the current day of the week

SELECT to_number(to_char(SYSDATE, 'DD')) to_day FROM dual; --to get the current date of the month

SELECT to_number(to_char(SYSDATE, 'MM')) to_month FROM dual; --to get the current month

SELECT to_char(SYSDATE, 'MM/DD') DD_MM FROM dual; --to get the current month/date 

hope above will helpful for your findings..


Forum|alt.badge.img+10
  • Author
  • Sidekick (Customer)
  • 119 replies
  • April 13, 2021

thx, I’ll try those.

 

To clarify, these two dates, 3/9 and 3/30, are sorting as 3/30, 3/9 instead of 3/9, 3/30 because it’s treating these as alphanumeric field type instead of Date.

Here’s the DataSource that shows it incorrectly sorted:

 

 


EntShehaM
Hero (Partner)
Forum|alt.badge.img+5
  • Hero (Partner)
  • 30 replies
  • April 13, 2021

So basically you need to order your weeks accordingly. Try using Order By week ASC (ascending order may help in this situation).


Forum|alt.badge.img+10
  • Author
  • Sidekick (Customer)
  • 119 replies
  • April 13, 2021

thx! I’ll try that...


Forum|alt.badge.img+10
  • Author
  • Sidekick (Customer)
  • 119 replies
  • April 14, 2021

This worked perfectly! Thanks!!!

SELECT to_char(SYSDATE, 'MM/DD')

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings