Solved

Calculated the Date in C#

Posted on 2014-02-26
5
252 Views
Last Modified: 2014-05-02
The system takes the current day you apply or check rates and adds the value in the Days to Close editor (30 days) to come up with an estimated closing date. From there, we figure out how many days are left in the month. If the estimated closing date falls on a Friday or the weekend, we moved the estimated closing date to the following Monday.
 
Using the application date or check rates date of 2/19/14, this means for your example, the average days to close is 30 which would put the closing date at March 20th. With a closing date of March 20th, the remaining days in the month would equal eight.

----Following is the code I had in C# but it is not calculating the Days Left In Month ----
---- It is calculating how many days left in a month ---

private state int retrieveInterestDays()
{
     var today = DateTime.Now;
     var day = today.Day;
     var daysinmonth = DateTime.DaysInMonth(today.Year, today.Month);

     return daysinmonth - day + 1;
}
0
Comment
Question by:eli411
[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
  • 4
5 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39889945
First of all, since you know that you are working with dates, do not create a var variable, create a DateTime. The compiler will be able to perform a better validation on your code, and you will gain a bit or performance.

Second, do not use DateTime.Now when you do not need the time. This can lead to problems later. Use DateTime.Today instead.

Thirdly, once you have a date, you can know which day of the week it falls with the DayOfWeek property, going from Monday (1) to Sunday(7).

Here is how I would perform you routine:

                  DateTime interestDate = DateTime.Today.AddDays(30);
                  while (interestDate.DayOfWeek>DayOfWeek.Thursday)
                  {
                        interestDate.AddDays(1);
                  }
0
 
LVL 2

Author Comment

by:eli411
ID: 39890281
Let me try and see if it work or not!  Thanks.
0
 
LVL 2

Author Comment

by:eli411
ID: 39890326
Hi JamesBurger:
   The purpose of this function I want to find out how many business day left for the month after adding 30 days!  I am still testing it.
0
 
LVL 2

Author Comment

by:eli411
ID: 40037965
I've requested that this question be closed as follows:

Accepted answer: 500 points for JamesBurger's comment #a39889945
Assisted answer: 0 points for eli411's comment #a39890326

for the following reason:

Very good!
0
 
LVL 2

Author Comment

by:eli411
ID: 40037963
Found solution from other web sites!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

For some reason Google Apps has decided to reserve 'www' for your new domain which results in an error when trying to map the web address 'www' to a certain site in your Google Sites. The error is 'this address is already being used' and after some …
The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…

762 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