Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

Get the last day of the curent month

using Date.Now how would i return the last date of that month

for example if today's date is 2012-11-14 I would like to return 2012-11-30
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

DateAdd(day,-Now.Day,DateAdd(month,1,Now))
Avatar of vbnetcoder
vbnetcoder

ASKER

This is asp.net code not SQL
I need to take date.now and return the last date of the month
I was using VB.Net code, though you would have to use the day and month system variables as the autocomplete provides (something like Interval.Day, only not quite that and I can't access VS right now to know for sure). Also works for C#.
Avatar of Seaton007
Are you talking about this:

DateTime.Today.AddMonths(1).AddDays(-1)

That gives me the date one month into the future. I want the LAST day of the current month.
You can use these below code to get days in month that you specific by year and month

 System.DateTime.DaysInMonth(2012, 11).ToString ()
You can also use:
DateSerial(Now.Year, Now.Month + 1, 1).AddDays(-1)
That gives me the date one month into the future. I want the LAST day of the current month.
DateSerial(Now.Year, Now.Month + 1, 1).AddDays(-1)  won't give you one month into the future. It will give you last day of this month.
ASKER CERTIFIED SOLUTION
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want, you can even use just:
DateSerial(Now.Year, Now.Month + 1, 0)
Thanks that worked.