Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2010, 10:04 PM
Registered User
 
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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))
 
Old June 29th, 2010, 05:44 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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:

Code:
Newdt = new DateTime(Newdt.Year, Newdt.Month, 1).AddMonths(1).AddDays(-1)
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old June 29th, 2010, 09:55 AM
Registered User
 
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hi

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.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding last day of a month John Anthony Access VBA 9 October 6th, 2008 03:27 PM
get year,month,day,hour... kobystud C# 1 July 16th, 2004 04:45 PM
Asp day of month display karib Classic ASP Databases 10 April 5th, 2004 12:56 AM
1st Week-Day of the Month ticktack Classic ASP Basics 2 January 19th, 2004 10:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.