Re: First Monday of the week



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

sweetpotatop@xxxxxxxxx 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
.



Relevant Pages

  • Re: Decompiler.NET reverse engineers your CLS compliant code
    ... Dim d2 As DateTime ' the ending date ... Dim theStartDate As DateTime ... > In other words "Human-Readable Code" or as Fowler states in Refactoring ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Decompiler.NET reverse engineers your CLS compliant code
    ... Dim d2 As DateTime ' the ending date ... Dim theStartDate As DateTime ... > In other words "Human-Readable Code" or as Fowler states in Refactoring ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Decompiler.NET reverse engineers your CLS compliant code
    ... Dim d2 As DateTime ' the ending date ... Dim theStartDate As DateTime ... > In other words "Human-Readable Code" or as Fowler states in Refactoring ...
    (microsoft.public.dotnet.languages.vc)
  • Re: VB.NET Insert Error into old version of Foxpro
    ... BEcause of the fact that the ODBC or OLEDB driver is of VFP, ... Date and datetime fields can be specified in multiple manners: ... > Dim cmdFox As New OleDb.OleDbCommand ...
    (microsoft.public.fox.programmer.exchange)
  • HELP with dataset update
    ... Private Sub DGDrVisits_UpdateCommand(ByVal source As Object, ... Dim row As DataRow 'for changing the datatable datarow ... Dim pAppropedDate As DateTime = ... @ApprovedDate datetime, ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)