

This is based on the fact that the last week of the year always includes 28 December. SELECT EXTRACT(WEEK FROM MAKE_DATE( yearcol, 12, 28)) FROM …. the number of the last week) in a year, get the week number of 28 December in that year using the above logic, i.e. Read more about TO_DATE() in the PostgreSQL manual. 2022), and weekcol is an ISO week number (1-53). To get the date of Monday in a given week, use SELECT TO_DATE(CONCAT( yearcol, weekcol), 'IYYYIW') FROM …. Read more about TO_CHAR() in the PostgreSQL manual. To get the week number in a TO_CHAR pattern, use IW for the week number and IYYY for the corresponding year. W - Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh. So in your test case, was on a Tuesday also, and a new 'week' as oracle calculates it. started on a Tuesday last year, not the first day of week. Read more about EXTRACT() in the PostgreSQL manual. WW - Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year. W - Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh. To get the corresponding four-digit year, use SELECT EXTRACT(ISOYEAR FROM datecol) FROM …. To get the ISO week number (1-53) from a date in the column datecol, use SELECT EXTRACT(WEEK FROM datecol) FROM …. The yellow color condition should be last one hour from sys time.Īction_dittime > ((sysdate – to_date(’0′,’DD-MON-YYYY’))-5) * (86400000)+to_number(to_char(systimestamp,’FF3′)) but this is not working properly.Week numbers in PostgreSQL How to get the week number from a date We are showing audit time format like mentioned in green color. SUBSTR(action_path.string_value,instr(action_path.string_value,’cm:’,-1)+3) AS FileName,įROM ALFDBSPRFSCMA.cisco_audit_entry_action_view action_view,ĪLFDBSPRFSCMA.cisco_audit_entry_path_view action_path,ĪLFDBSPRFSCMA.cisco_audit_entry_type_view type_view,ĪLFDBSPRFSCMA.cisco_view_user_info user_infoĪND action_path.string_value LIKE (‘/app:company_home/st:sites/cm:nextgen-edcs/cm:documentLibrary/%’)ĪND type_view.string_value =’cs:ciscodoc’ 50 which does not confirm with our working calender. If I convert (Sunday) to week number the result is week No.


Using the solutions above gave the following : if I convert to week number the conversion week is 51 which is OK. To_char(to_date(‘’, ‘YYYY-MM-DD’) + (action_dittime/ 86400000),’MM-DD-YYYY HH24:MI:SS’) as audittime Week start and end date for a given date Hi Tom,I want the sql to get the start of the week date and end of the week date for a given date and my week starts from saturday and ends with friday. Our first working day of the week is sunday. I have one doubt in oracle.I sent on query.I need last one hour data on that query. For example, YEAR, MONTH, HOUR, MINUTE, etc. We can get other date parts by changing it to the relevant keyword. (indt IN DATE,numweeks IN INTEGER) RETURN DATE. It’s the DAY keyword that extracts the day part from the date. Answer: To add weeks to an Oracle date you can this simple query: select sysdate, sysdate + (57) '5 weeks' from dual You can also use an addweeks function to add weeks to a date column: CREATE FUNCTION ADDWEEKS. Next_day(v_sysdate - (rownum * 7), dd) >= v_datechosenĭbms_output.put_line(v_weeksdiff||' '||to_date('&indate', 'mm/dd/yyyy')) ĭbms_output.put_line(v_dd ||' '||v_date) Here’s an example: SELECT EXTRACT (DAY FROM DATE '') FROM DUAL Result: 25. Select dd, next_day(v_sysdate - (rownum * 7), dd) DATE_Īnd next_day(v_sysdate - (rownum * 7), dd) >= v_datechosen V_weeksdiff number := round((sysdate - v_datechosen)/7) V_datechosen date := to_date('&indate', 'mm/dd/yyyy')
Where to_date('&indate', 'mm/dd/yyyy') <= sysdateĪnd next_day(sysdate - (rownum * 7), dd) >= to_date('&indate', 'mm/dd/yyyy')Ĭonnect by rownum <= round((sysdate - to_date('&indate', 'mm/dd/yyyy'))/7)note, greater than, equal, less than formatting might be affected by the tags In response to David’s query….cleaned up the dates that come out prior to the date entered as well as if you enter a date in the future. Select dd, next_day(sysdate - (rownum * 7), dd) DATE_įrom (SELECT 'MON' dd from CVT_T1_DAYS where mon = 1)Ĭonnect by rownum <= round((sysdate - to_date('', 'dd/mm/yyyy'))/7)įrom (SELECT 'TUE' dd from CVT_T1_DAYS where tue = 1)įrom (SELECT 'WED' dd from CVT_T1_DAYS where wed = 1)įrom (SELECT 'THU' dd from CVT_T1_DAYS where thu = 1)įrom (SELECT 'FRI' dd from CVT_T1_DAYS where FRI = 1) For David’s question on April 17th.I’m sure this could probably be cleaned up some more and I see that the Friday portion of this returns a friday before but this is a start…
