Solved

Using dtEnd.AddDays To Calculate Future Dates

Posted on 2014-01-07
4
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
dustock earned 125 total points
ID: 39762605
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
ID: 39762638
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
ID: 39762765
AndyAnscow - yes, there are values set before I use the AddDays function.
0
 

Author Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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