Solved

Calculated the Date in C#

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to packaging 1 90
Column Spacing 3 76
Best book to learn C++ 4 79
I've got an interview this morning and I want to sound intelligent... 4 50
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
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…

776 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