Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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))
  #2 (permalink)  
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?
  #3 (permalink)  
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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:20 PM.


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