Solved

Get the first day of next month

Posted on 2015-02-18
4
146 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 69

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 32

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now