Solved

Using dtEnd.AddDays To Calculate Future Dates

Posted on 2014-01-07
4
239 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

21 Experts available now in Live!

Get 1:1 Help Now