p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 3.5 Basics (http://p2p.wrox.com/forumdisplay.php?f=351)
-   -   adding months to get last day of month (http://p2p.wrox.com/showthread.php?t=79944)

WannaBeVb June 28th, 2010 10:04 PM

adding months to get last day of month
I need to add months and get the last day of the month. Rigth now i pass a variable whihc is my last value in my gridview which is a date called lastdate
so I need to add to last date to find the last day of the next month to populate it with my datagrid. Here is some code but doe not work right what am I doing wrong.

Newdt = DateAdd(DateInterval.Month, (Day(DateAdd(DateInterval.Month, 1, lastdate))) * -1, DateAdd(DateInterval.Month, 1, Newdt))

samjudson June 29th, 2010 05:44 AM

This is a .Net forum, yet you appear to be using the old VB style methods. These are in the compatibility layer, but things are usually much easier if you use the newer 'pure' .Net classes.

The following will give you the last day of the current month stored in newdt variable:


Newdt = new DateTime(Newdt.Year, Newdt.Month, 1).AddMonths(1).AddDays(-1)

WannaBeVb June 29th, 2010 09:55 AM

Thanks for the reply, I grabbed the code off the interweb and did not know what version it was other than it was not pulling the correct info.

All times are GMT -4. The time now is 06:45 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.