Solved

Calculated the Date in C#

Posted on 2014-02-26
5
247 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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 prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

895 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

17 Experts available now in Live!

Get 1:1 Help Now