Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In textbox I enter name of month like JAN 2015 or JANUARY 2015.
How can I get first date and end day of the month?
Posted
Updated 28-Jan-15 18:40pm
v2
Comments
Leo Chapiro 29-Jan-15 0:41am    
Is the first day of the month not always the 1. ? What have you already tried?
Sergey Alexandrovich Kryukov 29-Jan-15 1:17am    
Only on some special years this value can reach up to 1.42. :-)
—SA

You can find the first and last date using this code
Dim dt As DateTime = DateTime.Now
        TextBox1.Text = dt.Date
        TextBox2.Text = Format(dt.AddDays(-(dt.Day - 1)), "MM/dd/yyyy")
        Dim LastdayDate As Date = dt.AddMonths(1)
        TextBox3.Text = Format(LastdayDate.AddDays(-(LastdayDate.Day)), "MM/dd/yyyy")



try it
 
Share this answer
 
v3
Please see the top answer here: http://stackoverflow.com/questions/24245523/getting-the-first-and-day-of-a-month-using-a-given-datetime-instance[^].

The idea is very simple. If you have some point in time, you know its month. All you need to do is to create another point of time with the same month and first day. It makes you the 1st day. For a last day, you need a trick. Jump one month up, to get first day of next month. What would be the last day of previous month? Yesterday.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900