473,387 Members | 1,492 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,387 software developers and data experts.

Finding first saturday of month

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?
Jul 19 '05 #1
11 22412
"Solomon Grundy" <lo********@netscape.net> wrote in message
news:6a**************************@posting.google.c om...
| 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?

check out the NEXT_DAY function

;-{ mcs
Jul 19 '05 #2
Mark C. Stock wrote:
"Solomon Grundy" <lo********@netscape.net> wrote in message
news:6a**************************@posting.google.c om...
| 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?

check out the NEXT_DAY function

;-{ mcs


And be careful with trunc(sysdate):
SQL> select trunc(sysdate,'MM') from dual;

TRUNC(SYSDATE,'
---------------
01-FEB-04

--

Regards,
Frank van Bortel

Jul 19 '05 #3

"Frank van Bortel" <fv********@netscape.net> wrote in message
news:c1**********@news4.tilbu1.nb.home.nl...
| Mark C. Stock wrote:
| > "Solomon Grundy" <lo********@netscape.net> wrote in message
| > news:6a**************************@posting.google.c om...
| > | 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?
| >
| > check out the NEXT_DAY function
| >
| > ;-{ mcs
| >
| >
|
| And be careful with trunc(sysdate):
| SQL> select trunc(sysdate,'MM') from dual;
|
| TRUNC(SYSDATE,'
| ---------------
| 01-FEB-04
|
| --
|
| Regards,
| Frank van Bortel
|

frank,

the OP was intending to use trunc(sysdate,'MM'), which reliably returns the
first day of the current month -- in what way are you suggesting to be
careful with trunc(sysdate)?

;-{ mcs
Jul 19 '05 #4
Mark C. Stock wrote:
"Frank van Bortel" <fv********@netscape.net> wrote in message
news:c1**********@news4.tilbu1.nb.home.nl...
| Mark C. Stock wrote:
| > "Solomon Grundy" <lo********@netscape.net> wrote in message
| > news:6a**************************@posting.google.c om...
| > | 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?
| >
| > check out the NEXT_DAY function
| >
| > ;-{ mcs
| >
| >
|
| And be careful with trunc(sysdate):
| SQL> select trunc(sysdate,'MM') from dual;
|
| TRUNC(SYSDATE,'
| ---------------
| 01-FEB-04
|
| --
|
| Regards,
| Frank van Bortel
|

frank,

the OP was intending to use trunc(sysdate,'MM'), which reliably returns the
first day of the current month -- in what way are you suggesting to be
careful with trunc(sysdate)?

;-{ mcs


Well, for one, I got my wires crossed.
Apologies, forget about previous posting of mine.
OP is correct
--

Regards,
Frank van Bortel

Jul 19 '05 #5


"Solomon Grundy" <lo********@netscape.net> wrote in message
news:6a**************************@posting.google.c om...
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?


This appears to work for me:

trunc(to_date(year||month),'D')+6 from dual

zin
--- http://www.zintel.com
Jul 19 '05 #6

"George Ziniewicz" <zi**@cox.net> wrote in message
news:ZoQ0c.5727$506.3314@fed1read05...
|
|
| "Solomon Grundy" <lo********@netscape.net> wrote in message
| news:6a**************************@posting.google.c om...
| > 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?
|
| This appears to work for me:
|
| trunc(to_date(year||month),'D')+6 from dual
|
| zin
| --- http://www.zintel.com
|
|

zin,

you might want to try again (seriously, no sarcasm intended)

this expression (even with the added SELECT) doesn't run, and if it did,
adding 6 days to a date value only returns a saturday if the date is known
to be a sunday -- so to use something like this to find the first saturday
of the month, you'd have to first find the last sunday of the prior month

did you have something else in mind when you posted this?

;-{ mcs
Jul 19 '05 #7

"Mark C. Stock" <mcstockX@Xenquery .com> wrote in message
news:To********************@comcast.com...
|
| "George Ziniewicz" <zi**@cox.net> wrote in message
| news:ZoQ0c.5727$506.3314@fed1read05...
| |
| |
| | "Solomon Grundy" <lo********@netscape.net> wrote in message
| | news:6a**************************@posting.google.c om...
| | > 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?
| |
| | This appears to work for me:
| |
| | trunc(to_date(year||month),'D')+6 from dual
| |
| | zin
| | --- http://www.zintel.com
| |
| |
|
| zin,
|
| you might want to try again (seriously, no sarcasm intended)
|
| this expression (even with the added SELECT) doesn't run, and if it did,
| adding 6 days to a date value only returns a saturday if the date is known
| to be a sunday -- so to use something like this to find the first saturday
| of the month, you'd have to first find the last sunday of the prior month
|
| did you have something else in mind when you posted this?
|
| ;-{ mcs
|
|

woops -- my bad

spent a week working on MS-Access recently, so i mis-read the "D" format

however, 'D' truncation to the first day of the week does not always return
sunday -- it is dependent on the NLS_TERRITORY setting (then again, to a
degree, so was my solution using the NEXT_DAY function)

;-{ mcs
Jul 19 '05 #8
"Mark C. Stock" <mcstockX@Xenquery .com> wrote in message news:<M6********************@comcast.com>...
"Mark C. Stock" <mcstockX@Xenquery .com> wrote in message
news:To********************@comcast.com...
|
| "George Ziniewicz" <zi**@cox.net> wrote in message
| news:ZoQ0c.5727$506.3314@fed1read05...
| |
| |
| | "Solomon Grundy" <lo********@netscape.net> wrote in message
| | news:6a**************************@posting.google.c om...
| | > 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?
| |
| | This appears to work for me:
| |
| | trunc(to_date(year||month),'D')+6 from dual
| |
| | zin
| | --- http://www.zintel.com
| |
| |
|
| zin,
|
| you might want to try again (seriously, no sarcasm intended)
|
| this expression (even with the added SELECT) doesn't run, and if it did,
| adding 6 days to a date value only returns a saturday if the date is known
| to be a sunday -- so to use something like this to find the first saturday
| of the month, you'd have to first find the last sunday of the prior month
|
| did you have something else in mind when you posted this?
|
| ;-{ mcs
|
|

woops -- my bad

spent a week working on MS-Access recently, so i mis-read the "D" format

however, 'D' truncation to the first day of the week does not always return
sunday -- it is dependent on the NLS_TERRITORY setting (then again, to a
degree, so was my solution using the NEXT_DAY function)

;-{ mcs


I believe the SQL posted earlier may have a problem if the first day
of the month is a Saturday as my test found the next Saturday in this
case. (May is the only month in 2004 that starts on a Saturday)

Here is my attempt:
1 select next_day(last_day(add_months(sysdate,-1)),'Saturday')
2* from dual
@UT1 SQL>> /

NEXT_DAY(
---------
06-MAR-04

1 row selected.

If you substitute any date in May for sysdate it still produces
Saturday 1-May as the result.

HTH -- Mark D Powell --
Jul 19 '05 #9
lo********@netscape.net (Solomon Grundy) wrote in message news:<6a**************************@posting.google. com>...
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?

Try this
select trunc(sysdate,'mm')+(7- to_char(trunc(sysdate,'mm'),'d')) first_sat
from dual;

Replace sysdate with any date.
Jul 19 '05 #10
"Mark D Powell" <Ma*********@eds.com> wrote in message
news:26**************************@posting.google.c om...
| I believe the SQL posted earlier may have a problem if the first day
| of the month is a Saturday as my test found the next Saturday in this
| case. (May is the only month in 2004 that starts on a Saturday)
|
| Here is my attempt:
| 1 select next_day(last_day(add_months(sysdate,-1)),'Saturday')
| 2* from dual
| @UT1 SQL>> /
|
| NEXT_DAY(
| ---------
| 06-MAR-04
|
| 1 row selected.
|
| If you substitute any date in May for sysdate it still produces
| Saturday 1-May as the result.
|
| HTH -- Mark D Powell --

good solution

here's the one that i thought i had posted earlier and never did:

select next_day(trunc(sysdate,'MM')-1,'sat') first_sat
from dual

which skins the same cat but with one less function; it also works for may:

;-{ mcs
Jul 19 '05 #11
"Mark C. Stock" <mcstockX@Xenquery .com> wrote in message news:<V7********************@comcast.com>...
"Mark D Powell" <Ma*********@eds.com> wrote in message
news:26**************************@posting.google.c om...
| I believe the SQL posted earlier may have a problem if the first day
| of the month is a Saturday as my test found the next Saturday in this
| case. (May is the only month in 2004 that starts on a Saturday)
|
| Here is my attempt:
| 1 select next_day(last_day(add_months(sysdate,-1)),'Saturday')
| 2* from dual
| @UT1 SQL>> /
|
| NEXT_DAY(
| ---------
| 06-MAR-04
|
| 1 row selected.
|
| If you substitute any date in May for sysdate it still produces
| Saturday 1-May as the result.
|
| HTH -- Mark D Powell --

good solution

here's the one that i thought i had posted earlier and never did:

select next_day(trunc(sysdate,'MM')-1,'sat') first_sat
from dual

which skins the same cat but with one less function; it also works for may:

;-{ mcs


Yes, the elimination of one more function should be beneficial
whenever this has to be applied to thousands of rows. I will have to
remember that you can format in the trunc and not just work with the
results: date w/o time.

-- Mark D Powell --
Jul 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
20
by: Gav | last post by:
I have a database with date of births stored dd/mm/yyyy (english dating system) and =date() returns a date in the same format in my server. how do i find the persons age using these two pieces of...
5
by: Parintas Themis STE Kardias | last post by:
Hi How can i have in a textbox the first sunday of a month
2
by: planetthoughtful | last post by:
Hi All, I'm building some reports in Acc97 and using a custom calendar form to allow users to pick dates with which to report. I'm wondering if there's an easy way in code to be able to...
3
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 and I was wondering if anyone knows of a function or quick way, given a scalar representation of month (as a number between 1 and 12), day, and year (as a four digit...
3
by: foxykitty | last post by:
Hi, How can I group in my qryMonthlyHours in SQL view by , and then sum done in that month? I have another query - qrySaturdayRota ,,,,, ALL THIS IS GROUPED EXCEPT FOR has a criteria...
10
by: kyosohma | last post by:
Hi, I am working on a timesheet application in which I need to to find the first pay period in a month that is entirely contained in that month to calculate vacation time. Below are some example...
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?
8
code green
by: code green | last post by:
I need to generate the date for the latest Friday and the Saturday previous to this ie 7 days. I am generating reports for the periods Yesterday, Month to date and Sat-Fri so I create the dates in...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.