Solved

# Get the first day of next month

Posted on 2015-02-18
146 Views
This returns next month 03/18/2015. How can I get the begining of next month, 03/01/2015?

0
Question by:VBdotnet2005

LVL 69

Assisted Solution

Éric Moreau earned 125 total points
ID: 40617131
dt = new datetime(dt.year, dt.month, 1)
0

LVL 33

Assisted Solution

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());
``````
0

LVL 32

Assisted Solution

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"))
End Sub
End Module
``````
Produces the following output --saige-
0

LVL 62

Accepted Solution

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)
``````
0