Solved

Get the first day of next month

Posted on 2015-02-18
4
154 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 125 total points
ID: 40617131
dim dt = DateTime.Today.AddMonths(1).ToString("MM/dd/yyyy")
dt = new datetime(dt.year, dt.month, 1)
0
 
LVL 33

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 125 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 33

Assisted Solution

by:it_saige
it_saige earned 125 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 62

Accepted Solution

by:
Fernando Soto earned 125 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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