?
Solved

Get the first day of next month

Posted on 2015-02-18
4
Medium Priority
?
175 Views
Last Modified: 2015-02-18
This returns next month 03/18/2015. How can I get the begining of next month, 03/01/2015?

dim dt = DateTime.Today.AddMonths(1).ToString("MM/dd/yyyy")
0
Comment
Question by:VBdotnet2005
4 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 500 total points
ID: 40617131
dim dt = DateTime.Today.AddMonths(1).ToString("MM/dd/yyyy")
dt = new datetime(dt.year, dt.month, 1)
0
 
LVL 34

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
ID: 40617134
        DateTime firstDay;
        DateTime myDate = Convert.ToDateTime("2/19/2015");
        int mon = myDate.Month;
        int year = myDate.Year;
        firstDay = new DateTime(year, mon, 1);
        Response.Write(firstDay.ToString());

Open in new window

0
 
LVL 35

Assisted Solution

by:it_saige
it_saige earned 500 total points
ID: 40617139
More simplified approach:
Module Module1
	Sub Main()
		Dim dt = New DateTime(Now.Year, Now.Month, 1).AddMonths(1)
		Console.WriteLine(dt.ToString("MM/dd/yyyy"))
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40617162
Hi VBdotnet2005;

This should give you what you need.

Dim MyDate As Date = DateTime.Today
Dim DaysInMonth As Integer = DateTime.DaysInMonth(MyDate.Year, MyDate.Month)
Dim MonthStartDate As String = New DateTime(MyDate.Year, MyDate.Month, DaysInMonth).AddDays(1)

Open in new window

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 20 hours left to enroll

864 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