473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to get the last saturday of a month?

How to get the last saturday of a month?
Sep 16 '10 #1
3 19173
OraMaster
135 100+
Expand|Select|Wrap|Line Numbers
  1. SELECT TO_CHAR
  2.           (NEXT_DAY (LAST_DAY (TO_DATE ('SEP', 'MM')) - 7,
  3.                      TO_CHAR (TO_DATE ('29-01-1927', 'DD-MM-YYYY'), 'DAY')
  4.                     ),
  5.            'DD.MM.YYYY'
  6.           ) "Last Saturday of SEP-2010"
  7.   FROM DUAL;
Sep 16 '10 #2
amitpatel66
2,367 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1* select NEXT_DAY(LAST_DAY(SYSDATE) - 7,'SATURDAY') from dual
  5. SQL> /
  6.  
  7. NEXT_DAY(
  8. ---------
  9. 25-SEP-10
  10.  
  11. SQL> 
  12.  
  13. -- for the complete year
  14.  
  15. SQL> ed
  16. Wrote file afiedt.buf
  17.  
  18.   1  SELECT TO_CHAR(dat,'MON-RRRR') MOn_Year,MAX(dat) Last_Saturday
  19.   2  FROM
  20.   3  (select TRUNC(SYSDATE,'RRRR') + level - 1 dat,level lvl FROM
  21.   4  dual
  22.   5  connect by level <= TO_DATE('31-DEC-'||TO_CHAR(SYSDATE,'RRRR')) - TRUNC(SYSDATE,'RRRR') + 1)
  23.   6  WHERE TO_CHAR(dat,'dy') = 'sat'
  24.   7* GROUP BY TO_CHAR(dat,'MON-RRRR')
  25. SQL> /
  26.  
  27. MON_YEAR       LAST_SATU
  28. -------------- ---------
  29. APR-2010       24-APR-10
  30. AUG-2010       28-AUG-10
  31. DEC-2010       25-DEC-10
  32. FEB-2010       27-FEB-10
  33. JAN-2010       30-JAN-10
  34. JUL-2010       31-JUL-10
  35. JUN-2010       26-JUN-10
  36. MAR-2010       27-MAR-10
  37. MAY-2010       29-MAY-10
  38. NOV-2010       27-NOV-10
  39. OCT-2010       30-OCT-10
  40. SEP-2010       25-SEP-10
  41.  
  42. 12 rows selected.
  43.  
  44. SQL> 
  45.  
  46.  
Sep 20 '10 #3
Expand|Select|Wrap|Line Numbers
  1. select next_day(last_day(sysdate)-7*level,'Saturday') from dual connect by level <=1;
Jul 17 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: N8tor | last post by:
I'm a programming neophyte so needless to say I need some help on some VB scripting. I need to create some code to find what month it will be this coming Saturday. I also need to do the same...
11
by: Solomon Grundy | last post by:
Select trunc(sysdate,'MM') from dual of course gives me the first day of the month, may I ask what the query is to find the first saturday of the month?
7
by: Bob | last post by:
I passed in a DateTime object, and want to get its end date of the month. Is there a easy way to do it? Thanks.
34
by: prosoft | last post by:
When I use Dim myDTFI As DateTimeFormatInfo = New CultureInfo("he-IL", True).DateTimeFormat Dim strhmon1 As String = (myDTFI.GetMonthName(hmon1)) MsgBox(strhmon1) I get the local name of the...
1
by: Frank Bishop | last post by:
I have been spoiled by some report writing tools that have intrinsic functions like Last Year Month-to-date. I'm looking for a way to emulate this in SQL Server now with my fields that are...
0
by: larry | last post by:
I am in the process of rewriting one of my first PHP scripts, an event calendar, and wanted to share the code that is the core of the new calendar. My current/previous calendar processed data...
3
by: ats | last post by:
Does anybody have any sample code for calculating the date for teh last Friday in each month. TIA -- ats@jbex When an old lady got hit by a truck I saw the wicked gleam in your eyes
0
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and...
1
Asutosha
by: Asutosha | last post by:
Hi, i want to create a cross tab report in vs 2005+sql server 2000. My table name is "RepMonthlySales" having Columns (RepCode,repname,Accntref,AccntName,Qty, Year, MonthName,Sales ) ...
1
by: karuppiah | last post by:
Hi All, i need query,how to select last 3 month ,last 3wek,last 3 days , this last 3 month and 3 week should be friday, using sysdate from dual table, there is no exsting table, pls any one help...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.