vj_mi
asked on
Getting date with last day of the month
The user enters date. Now from that I need to modify the date entered in such a way that I get the date with the last day of the month. For example, if user enters 12/12/2007, then I want the code to modify this value to 31/12/2007. Or if it is 12/2/xxxx, then I should get 28/2/xxxx or 29/2/xxxx. How can I do that?
Regards,
MI
Regards,
MI
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this
DateTime dt1 = DateTime.Now;
Response.Write( (dt1.AddDays(-(DateTime.No w.Day -1 ))).AddMonths(1).AddDays(- 1));
DateTime dt1 = DateTime.Now;
Response.Write( (dt1.AddDays(-(DateTime.No
You can use Date.Year() and Date.Month() instead of Microsoft.VisualBasic.Mont
Re-written as a "one liner":
Private Function LastDayOfMonth(ByVal myDate As Date) As Date
Return New Date(myDate.Year, myDate.Month, DateTime.DaysInMonth(myDat
End Function
This is another common way it is done:
Private Function LastDayOfMonth(ByVal myDate As Date) As Date
Return New Date(myDate.Year, myDate.Month, 1).AddMonths(1).AddDays(-1
End Function