[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

finding first day and last day of current month vb.net

Posted on 2006-06-06
9
Medium Priority
?
6,150 Views
Last Modified: 2009-07-02
What is the easiest way to find the first and last day of the current month?
0
Comment
Question by:tentavarious
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:Tertioptus
ID: 16842424

       Dim d As System.DateTime = Now
        MsgBox(d.AddDays(d.DaysInMonth(d.Year, d.Month) - d.Day()).ToString("MM/dd/yyyy"))
0
 
LVL 71

Accepted Solution

by:
Éric Moreau earned 1000 total points
ID: 16842460
Hi tentavarious,

Hi have these methods in one of my class:

    Public Shared Function GetBeginOfCurrentMonth(ByVal pDate As Date) As Date
        Return Date.Parse(pDate.Year.ToString & "/" & pDate.Month.ToString & "/01")
    End Function
    Public Shared Function GetEndOfCurrentMonth(ByVal pDate As Date) As Date
        Return Date.Parse(pDate.Year.ToString & "/" & pDate.Month.ToString & "/" & pDate.DaysInMonth(pDate.Year, pDate.Month).ToString)
    End Function

Cheers!
0
 

Author Comment

by:tentavarious
ID: 16842697
Anyway you can get me the working days in  a month, basically subtract all sundays and saturdays
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 71

Expert Comment

by:Éric Moreau
ID: 16842712
Tertioptus,

You will need to loop through all days and checking if the day is a weekend or not
0
 
LVL 5

Expert Comment

by:Tertioptus
ID: 16842737
ohhh, okay, thanks
0
 

Author Comment

by:tentavarious
ID: 16842742
Could you give me a small example?
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 16842868
tentavarious,

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dtmTest As Date = cDateUtil.GetBeginOfCurrentMonth(Date.Today)
        Dim intWorkableDays As Integer

        Do While dtmTest <= cDateUtil.GetEndOfCurrentMonth(Date.Today)
            If dtmTest.DayOfWeek <> DayOfWeek.Saturday AndAlso dtmTest.DayOfWeek <> DayOfWeek.Sunday Then
                intWorkableDays += 1
            End If
            dtmTest = dtmTest.AddDays(1)
        Loop
        MessageBox.Show("there are " + intWorkableDays.ToString + " workable days")
    End Sub
0
 
LVL 5

Expert Comment

by:Melaleuca
ID: 24764930
why not just use this: it works in T-SQL and can be slightly altered to for VB using the NOW().
select DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)
0
 
LVL 5

Expert Comment

by:Melaleuca
ID: 24765518
OR:   =DateAdd("d",1-DatePart("d",Today()),Today())
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question