How to get the last saturday of a month?
3 19173 - SELECT TO_CHAR
-
(NEXT_DAY (LAST_DAY (TO_DATE ('SEP', 'MM')) - 7,
-
TO_CHAR (TO_DATE ('29-01-1927', 'DD-MM-YYYY'), 'DAY')
-
),
-
'DD.MM.YYYY'
-
) "Last Saturday of SEP-2010"
-
FROM DUAL;
-
SQL> ed
-
Wrote file afiedt.buf
-
-
1* select NEXT_DAY(LAST_DAY(SYSDATE) - 7,'SATURDAY') from dual
-
SQL> /
-
-
NEXT_DAY(
-
---------
-
25-SEP-10
-
-
SQL>
-
-
-- for the complete year
-
-
SQL> ed
-
Wrote file afiedt.buf
-
-
1 SELECT TO_CHAR(dat,'MON-RRRR') MOn_Year,MAX(dat) Last_Saturday
-
2 FROM
-
3 (select TRUNC(SYSDATE,'RRRR') + level - 1 dat,level lvl FROM
-
4 dual
-
5 connect by level <= TO_DATE('31-DEC-'||TO_CHAR(SYSDATE,'RRRR')) - TRUNC(SYSDATE,'RRRR') + 1)
-
6 WHERE TO_CHAR(dat,'dy') = 'sat'
-
7* GROUP BY TO_CHAR(dat,'MON-RRRR')
-
SQL> /
-
-
MON_YEAR LAST_SATU
-
-------------- ---------
-
APR-2010 24-APR-10
-
AUG-2010 28-AUG-10
-
DEC-2010 25-DEC-10
-
FEB-2010 27-FEB-10
-
JAN-2010 30-JAN-10
-
JUL-2010 31-JUL-10
-
JUN-2010 26-JUN-10
-
MAR-2010 27-MAR-10
-
MAY-2010 29-MAY-10
-
NOV-2010 27-NOV-10
-
OCT-2010 30-OCT-10
-
SEP-2010 25-SEP-10
-
-
12 rows selected.
-
-
SQL>
-
-
- select next_day(last_day(sysdate)-7*level,'Saturday') from dual connect by level <=1;
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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?
|
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.
|
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...
|
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...
|
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...
|
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
|
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...
|
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 )
...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
| |