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

First Monday of the week

Hi,

I wonder if there is any function in VB or SQL that will return the
date of first Monday of the Monday.

Besides, is there are a way finding the numbers of Monday in a month?

Thanks in advance. Your help is greatly appreciated.

Jun 12 '07 #1
4 6503
Hi,

http://msdn2.microsoft.com/en-us/lib...ek(VS.71).aspx

if you don't know how to get the week from the datetime, have than a look at
our website.
www.vb-tips.com

Cor

<sw**********@yahoo.comschreef in bericht
news:11**********************@z28g2000prd.googlegr oups.com...
Hi,

I wonder if there is any function in VB or SQL that will return the
date of first Monday of the Monday.

Besides, is there are a way finding the numbers of Monday in a month?

Thanks in advance. Your help is greatly appreciated.

Jun 12 '07 #2


<sw**********@yahoo.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
Hi,

I wonder if there is any function in VB or SQL that will return the
date of first Monday of the Monday.
The first Monday of Monday? I assume you mean the first Monday of the month
:D I am pretty sure there is, but I don't remember..maybe it is SQL that I
remember having such a method....
Besides, is there are a way finding the numbers of Monday in a month?
The following should work for ya.
Private Function GetDayOfWeekCountForMonth( _
ByVal Month As Integer, _
ByVal Year As Integer, _
ByVal DayOfWeek As DayOfWeek _
) As Integer
Dim count As Integer = 0
Dim d As Date = New Date(Year, Month, 1)

While d.Month = Month AndAlso d.Year = Year
If d.DayOfWeek = DayOfWeek
count += 1
d = d.AddDays(7)
Else
d = d.AddDays(1)
End If
End While

Return count
End Function

Jun 12 '07 #3
The first monday of the week? As far as I know, there are rarely more
than one monday in a week... ;)

sw**********@yahoo.com wrote:
Hi,

I wonder if there is any function in VB or SQL that will return the
date of first Monday of the Monday.
Neither does mondays often contain more than one monday... ;)

There is no built in function to return the first monday of a month. You
can get the weekday of the first day of the month, and use that to
determine how many days to add to get to the monday.

Something like:

Dim first as DateTime = New DateTime(year, month, 1)
Dim day as Integer = Cast(first.DayOfWeek, Integer)
If day <= 1 Then day = day + 7
Dim firstMonday as DateTime = first.AddDays(8 - day)
Besides, is there are a way finding the numbers of Monday in a month?
One way could be to just repeatedly add seven days to the date until it
reaches the next month.

--
Göran Andersson
_____
http://www.guffa.com
Jun 12 '07 #4
HI,

Guys is this not enough for an obvious typo?

Cor

<sw**********@yahoo.comschreef in bericht
news:11**********************@z28g2000prd.googlegr oups.com...
Hi,

I wonder if there is any function in VB or SQL that will return the
date of first Monday of the Monday.

Besides, is there are a way finding the numbers of Monday in a month?

Thanks in advance. Your help is greatly appreciated.

Jun 13 '07 #5

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

Similar topics

2
by: Targa | last post by:
Need to print "Week of (first day of week)" First day being Monday. ie: week = Request.querystring("mydate") response.write "Week of" & week If week = 5/6/2004 (which is Thursday) it should...
3
by: CrystalDBA | last post by:
I am using SQL Server 2000. I need to query my database for all the contracts that came in during a certain time frame (user is prompted for reportingperiodid). Table - Periods Fields -...
5
by: Martien van Wanrooij | last post by:
I would like to retrieve, let us say, the First Monday after a certain date, so my (imaginary) function could be something like echo weekdayAfter("28 July 2005", "Monday") should return "1 August...
5
by: Hardy Wang | last post by:
Hi: Are there any algorithms I can use, that based on a given date and a culture code (different cultures may have different beginning of week), I can get first and last date of the current week?...
4
by: Morten Wennevik | last post by:
In an earlier thread I said first day of week was defined as monday, not sunday and forgot all about the thread, so I never got to reply on where it says that. So here it is. ISO 8601 -...
5
by: Drum2001 | last post by:
Currently I am running the following query: SELECT DateFilter.Employee, DateFilter.TimeTypeIn, sectodur(IIf(Sum(DateDiff("s",,))-40*60*60>0,Sum(DateDiff("s",,))-40*60*60,0)) AS Overtime,...
7
by: bojan.pikl | last post by:
Hi, I am making a calendar. It is costum made and I would like to have the ability to choose the first day (Monday or Sunday). I know for the firstDayOfWeek, but I can't change it. What should I...
3
by: Simon | last post by:
Dear reader, By using the command: DatePart("ww";)
5
by: Chris | last post by:
I am trying to output Monday of the current week i.e. if Monday is the 8th I want to display 'Monday 8th' for any date between Monday 8-14th. I would appreciate any help, the code below is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.