Solved

Using dtEnd.AddDays To Calculate Future Dates

Posted on 2014-01-07
4
237 Views
Last Modified: 2014-01-07
I have an app that includes a calendar that allows users to select dates.   The customer wants to allow the users to schedule their meetings with this web page.  The user selects a date (like today) from a calendar.  Then, they enter a number in a field.  The code needs to calculate today's date plus the number of years entered in the text box and display that as a date.  Example:  today plus 5 years = 1/7/2019.

Here is the code that I'm trying to use to perform the calculation:
  {
        DateTime myStartDate, myEndDate;
        myEndDate.AddDays  (this displays the date selected by the calendar)

Open in new window


Is there a tutorial or webpage that displays the proper formatting to do what I'm trying to do?  I've tried myEndDate.AddDays(1), myEnddate.addDays(-1), etc but nothing works.  As you can tell, I am new to this so any help is appreciated.
0
Comment
Question by:programmher
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 125 total points
Comment Utility
As stated on MSDN

"This method does not change the value of this DateTime. Instead, it returns a new DateTime whose value is the result of this operation."

So the Add days is working, it just looks like you aren't doing anything with the value.  Try this...
myEndDate = myEndDate.AddDays(1);

Open in new window

0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 125 total points
Comment Utility
I assume you do actually set a value into myEndDate before you use the AddDays function (in the way as previously pointed out you need to).

DateTime myStartDate, myEndDate;
//put a value into myEndDate at this point
        myEndDate = myEndDate.AddDays  (this displays the date selected by the calendar)
0
 

Author Comment

by:programmher
Comment Utility
AndyAnscow - yes, there are values set before I use the AddDays function.
0
 

Author Comment

by:programmher
Comment Utility
Dustrock - you are correct - my function was working.   I had someone validate that for me.  Thank you for your help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now