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

Need help with dayofweek function

I am trying to calculate the number of Mondays, Tuesdays, Wednesdays, etc in any given month. Example...in September 2008 there are 5 Mondays. 4 Fridays, etc. Does anyone know a SQL statement that does this.
Sep 18 '08 #1
1 2521
docdiesel
297 Expert 100+
Hi,

I think there's no easy sql to calculate this. But you may use some date related functions to calculate what you need:

Given you've got to calculate the number of weekdays for February 2008:
Expand|Select|Wrap|Line Numbers
  1. select day(date('2008-02-01') + 1 month - 1 day) from sysibm.sysdummy1
gives you the number of days in the given month, resulting in an integer from 28 to 31.
Expand|Select|Wrap|Line Numbers
  1. select dayofweek_iso(date('2008-02-01')) from sysibm.sysdummy1
gives you the number of the day of the week for the first of the month (1=Monday, 7=Sunday), so you can calculate which days count up to 5 instead of 4.

Please let us know how you solved it so that others may participate.

Regards


Doc Diesel
Sep 19 '08 #2

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

Similar topics

7
by: Consuelo Guenther | last post by:
Hello, I have an asp page that has a function that connects to an Access database. I am using Javascript. Is there any way to reference the field name in the database through a variable in a sql...
5
by: JJ | last post by:
Hi all, whats wrong with the following code: DateTime calcDate = new DateTime(); DateTime dDate = DateTime.Now; if (calcDate.DayOfWeek(dDate) != "Saturday") || (calcDate.DayOfWeek(dDate)...
3
by: Stuart Shay | last post by:
Hello All: I have some old ASP Code where it use the WeekdayName Function How Can I get the following values in C# wday = 1; => Sunday wday = 4; => Wednesday I see VB.NET has the...
8
by: simon | last post by:
dateTime sellDate; int16 dayOfWeek; dayOfWeek=sellDate.DayOfWeek I would like to set that monday is the first day of a week and not sunday. Any idea? In VB there is a function, where you...
0
by: Harry Haller | last post by:
The context is shown below in the getGames() method. I get errors on these lines: dtGames.Rows = (TimeSpan)dtGames.Rows; dtGames.Rows = (DayOfWeek)dtGames.Rows; because the playDate column...
5
by: What-a-Tool | last post by:
Have a group of dynamically created text boxes in a calendar like grid. At the head of each column, the textbox is to contain the day of the week. Now I am using a Select Case statement to...
16
by: pankaj_wolfhunter | last post by:
Greetings, In DB2, we have dayofweek function that returns a numeric value for the current day (1 for sunday till 7 for saturday) Is it possible to alter this function value, i mean 1 for monday...
3
by: RSH | last post by:
Hi, Does anyone have a function that returns the day of week (Sun-Sat) from a user supplied date (4/12/2006). Thanks! Ron
3
by: Charlie Brown | last post by:
I am trying to cast a string to System.DayOfWeek. Don't even know if this is possible but it would sure save me a lot of headache if it is. Trying... Dim strDay As String = "Wednesday" Dim...
1
by: skhairnar | last post by:
Hi All, I am trying to write a validation rule for DateTimePicker, which will prevent user from selecting saturday or sunday as a value. For this I have added an event handler with following code:...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.