Solved

Calculated the Date in C#

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
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…

759 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

18 Experts available now in Live!

Get 1:1 Help Now