Solved

Get the first day of next month

Posted on 2015-02-18
4
157 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 34

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 63

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

792 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