Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to determine weeknumbers from two dates.
I have a query in Access DB which looks like this. I am trying to achieve same query in Oracle. How do i do it? I have written a query but it does not seem like right.

IIf(Weekday([HiredDate])=7,[HiredDate],[HiredDate]-Weekday([HiredDate])) AS TrainingStart, 
Date()+6-Weekday(Date()) AS EndOfWeek, 
DateDiff("ww",[TrainingStart],[EndOfWeek]) AS WeekNumber,


What I have tried:

SELECT Name, HiredDate, 
(CASE WHEN (to_char(to_date(HiredDate), 'd') = 7) THEN HiredDate ELSE (HiredDate - to_char(to_date(HiredDate), 'd')) END) as StartDate, 
(CURRENT_DATE + (6 - to_char(to_date(CURRENT_DATE), 'd'))) as EndDate,
(To_Number(to_char(to_date((CURRENT_DATE + (6 - to_char(to_date(CURRENT_DATE), 'd')))),'WW')) - To_number(to_char(to_date((HiredDate - to_char(to_date(HiredDate), 'd'))),'WW')) +1) as WEEKNUMBER 
FROM employee;
Posted
Updated 25-Jul-19 22:29pm
Comments
CHill60 26-Jul-19 4:14am    
What are the results of your query. Do you have some sample data and expected results

1 solution

To convert your Access query to Oracle …

Don't change the IIf - it also exists in Oracle - see IIF - Oracle Help Center[^]

Don't change the Weekday() - that function also exists in Oracle - see WeekDay - OracleDocs[^]

To replace DateDiff() you can just subtract one date from the other - see Data Types - OracleDocs[^]

To Replace the Date() function use either CURRENT_DATE[^] or SYSDATE[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900