C# - Calculating Corresponding Calendar Day Of Previous Years
Mar 30, 2011
I have the following beast of an SQL (DB2) statement...
[Code]...
Taking the input date of Wednesday, 2012-03-28, this would return Wednesday, 2006-03-29. Notice that it matched the Thursdays. It matches the corresponding calendar day of previous years. Is there a more elegant way of accomplishing the same goal in C# or VB.NET? I've tried translating this query into VB.NET, but haven't been able to do so perfectly and it just looks horrible and unmaintainable.
Suppose $800 is deposited into a savings account earning 4% interest compounded annually, and $100 is added to the account at the end of each year. Calculate the amount of money in the account at the end of 10 years. Determine a formula for computing the balance at the end of one year based on the balance at the beginning of the year.Allow the user to input the beginning balance and the amount to be contributed at the end of each year. You must a loop in this program. [code] I cannot figure out how to make the previous years balance become the next years and so forth.
I am trying to calculate the exact amount of time in Years, Months and Days between 2 date values. I'm getting stuck on the day calculation. I've returned the # of months and it's value is 8.77. The .77 needs to be rounded to 8 which should give me the days. I'm not exactly sure what MATH function to use to do this.
I am writing an application for my class, wherein I have a mortgage that will give the customer a discount of 1% on their interest if they pay early in the month, or penalize them by 1% if they are after the due date. Right now, I have it working with a checkbox that the user selects. However, I would like to have VB see the current date on the calendar I placed in the application already, and calculate the appropriate amount of interest based on that information. I am using Microsoft 2008 Visual Basic Express Edition on a PC.
I'm creating a report in MS SQL Server Reporting Services and need to set the default Start and End Date report parameters to be the first and last dates of previous calendar month and need help.The report is generated on the 2nd calendar day of the month and I need values for:
Previous Calendar Month - first day - last day
I've been working with DateAdd, but have not been successful at creating an Expression (in VB.NET as I understand it).
using the calendar from the webfor tools, NOT CALENDAR EXTENDER, and my question is, is there a way to add text to a specific day of the calendar, for example, that i want to click on the number where its shows 29 of the month december, then it shows me a texbox or anything that takes data from my, and i type anything in there, like an event or something, then i click on a button to save my entry, and next time i visit my page i see that day that i clicked on changed its color and shows my text when i hoover the mouse on top of it,
I'm developing a finance software and I want the user to enter a bill and pick the due date via month calendar. I getting it to work was the easy part, but now I only want one month calendar, for each time a user enters in a bill and picks a date.every time the user goes to pick a due date I have to call one of the several I have on screen.Here is my code that I have so far:Add due date button:
I am stuck, I am doing a Case Statment and this loop to calculate pay per hour and thexpected raise percentage on 40 hr week @ 52 wks per yr. THe raise increase each amount after the first year.The display for next 10 years is the head bump. Any suggesions will be tried. In this loop trying to get the 1 year values to add the intrest rate to the following 10 years is something I can not seePrivate Sub btnCalculatePay_Click(ByVal sender As System.Object, ByVal e As ystem.EventArgs) Handles btnCalculatePay.Click
I am trying to figure out how to calculate the number of years it takes to double a user defined number. I have tried to take the number entered and multiply it by twelev and divide by two.
I have a project that I am working on that requires me to delete records from the database if they are atleast 3 years old.I have something like this in DB2 SQL to get the date:
SELECT * FROM tableA WHERE ADD_DATE < CHAR(CURRENT DATE-3 YEARS)
ADD_DATE is stored as Characters in my system, this is why I am converting I know it is also possible to get the date and format it in VB.net which is the language I am using to call the SQL statements.My question is whether it would be faster/better to get the date and perform the conversion inside the SELECT in SQL or would it be better to get the current date and convert it in VB.net and then use that date in the SQL statement. I'm thinking VB.net would be better because there are thousands of records that must be compared. I should be able to set it up in VB so that it only retrieves the date and converts it once but I am not sure what kind of performance hit each takes from these statements.
I am new to VB 2010 and I am trying to right an application that takes in 2 years as inputs with in 0-3000 and displays all leap years in between and to check if the years are valid and output a message box if not.
I know that Every year that is evenly divisible by four is a leap year;
b.of those years, if it can be evenly divided by 100, it is NOT a leap year, unless
c.the year is evenly divisible by 400. Then it is a leap year.
But I cannot figure out how to put this into code. I have been looking up and trying tutorials all weekend.
I am having trouble with code for list box of Leap Years between a certain start date and end date.I understand the cose for finding out if a particular year is a leap year, but what I need to to is have all leap years show in a list box, once one has entered a start date (year) and an end date(year).
I am working on a code where I need to add 21 years to the date 02/15/1957 and have it display the week day of that year. I have been looking at different web sites for visual basic
Create a project that determines the future value of an investment at a given interest rate for a given number of years. The formula for the calculation is Future value = Investment amount * (1 + Interest Rate)^ Years..Form- Use labeled text boxes for the amount of investment, the interest rate (as a decimal fraction), and the number of years the investment will be held. Display the future value in a text box formatted as currency. Include buttons for calculate, Clear, Print, and exit. Format all dollar amounts. Display a message to the user for nonnumeric or missing input data.Remember that the result of an exponentiation operation is a Double data type. Interest rate is annual.So far this is what I have and I am missing something(s) in the calculate process.[code]
Consider the following 2 scenarios: Scenario 1). Today is May 1st 2012, and Scenario 2). Today is September 1st 2012.Now, consider that we write on our webpage the following about a comment someone has left: "This comment was written 3 months and 12 days ago". The amount of days in both these scenarios will ALWAYS be different even though the statement is exactly the same. In Scenario 1, "3 months and 12 days" would equal 102 days. However, in Scenario 2, "3 months and 12 days" would be 104 days!Now, to corner in on my point, lets use a different example and say that someone left a comment on our site on Jan 30th 2013, and today is March 10th 2013. Our real TimeSpan object needs to know this relative date, and can figure out the following:
That there is 10 days in March,That there is 1 day in Jan (counting from 30th to 31st).That the month Feb is one month regardless of how many days there are in it (even though it's 28 days).So, it would mean 10 days + 1 day + 1 month total, translating to This comment was posted 1 Month and 11 Days ago.Now, if you used the MS style TimeSpan object (or any TimeSpan object in any language), it would give you the number of days from 30th Jan to 10 March (39 days), and because the TimeSpan object doesn't store relative date (the base/initial date we subtracted to get the TimeSpan), if you asked it how many months and days it has been, it will assume there is 30 days in one month, or even worst, the average which is greater than 30 days, and return the rest in days, so to get to 39 days, it will tell you it's been 1 Month and 9 Days and you will get the This comment was posted 1 Month and 9 Days ago message. Remember, both these scenarios have the same start date and same current/end date, yes the Microsoft TimeSpan object, by not allowing us to tell it the month of Feb 2013 should be be considered, has given us a completely different TimeSpan, off why a whole 2 days. It has, in effect, lied to us.
The problem is, people will believe this, and who knows what perceptions they may have, how their perceptions of the past may change and the decisions & life choices they may make when trying to reconstruct events within the past inside their own minds, while never noticing or understanding the drawback and inherent failure of representing time that is so pervasive everywhere today. They will not understand that programming languages don't realize (or care) that last month had 31 days in it, as oppposed to 30, 29 or 28 - or visa versa, and that this adds up when you increase the TimeSpan.
This is the problem at the heart of this post. I understand that most people will not care about this difference (but be sure that some of us do, and cannot have this on our backs), and if this doesn't bother you, thats ok. I wish it didn't bother me, I would have saved myself some time, stress and disappointment. If this is not a bother, you can use the function for the efficient textual display of relative time (customizable to 1 to 6 nodes from seconds to years), instead of using it for the usually negligible accuracy it provides.
To my disappointment I noticed that there is no real timespan object, if you get a timespan, and do a .years or .months you'll get nothing, you'll only get .days and lower because a timeSpan object doesn't carry anything to tell it which month or year the timeSpan was created on. Therefore it'll never really know how many months it's been since days in each month vary over a year and even further over a leap year.I figured there'd be a ...
timeSpan.GetActualNumberOf[Months/Days/Hours/etc] (base date must be provided of course)
... type method on this datatype, but there wasn't.All you'd really have to do is create another property on the timeSpan object to give it a base date on which the difference was calculated, then the above lovely string would be calculable pretty easily, and a .year & .month would exist!
I'm trying to use a combobox to pull the current year and then populate the next ten years. I don't want to manually put in the years in the 'item collections'. I would rather it update automatically based on the system year. How should I go about doing this?
My first instinct is to set the combobox item to the current year based on the system date, then create a loop that increments based on on counter up to current year + 10. I'm assuming this would be done on the 'form_load' event handler???
I want to get the total years and months in a number eg. 25 should give me 2 years 1 month. and 11 should give me 0 years 11 months and maybe 12 should be 1 year 0 months,i have this code but it does work for me as i want it seems the loop i am using goes only once.
Dim Month As Double = 25 Dim LeftMonth As Double Dim Count As Integer = 0
I've been given two dates that takes their values from two respective dtpickers.I've got to calculate the exact amount of days, months and years between them.[code]The problem is that this function gives me ALL the amount of respective days, months and years passed, but I need to split them up in the correct way. Ex, between 28/2/98 and 13/1/2007 the result should be 15 days, 10 months and 8 years. And above all, the result is that the function indicates one month more (or one year more) with only one day (or month) passed between the two dates!
Suppose you have three file of a database with information for three years (imported information of one year to database and has saved as a new file). How we can merge this three file and create one database for all years with visual basic 2010?
Note:
1-Each database has three tables and there is relationship between them
2- The ID number in tables is Auto number
3- Fields in all tables for all files are completely the same
I am now want to retrieve only year from my table(summary),field name(dates). So i am facing the problem on how to display the year in combo Box. my sql statement as below.
I need to save actual age (in whole years) for future use in the program. The problem is, 'Years' returns a big, fat 0 every time. Changing "Dim years As Integer" to Dim years As String" does exactly the same thing.
Code: Dim myDate = New Date(Convert.ToInt32(Year.Value), Month.SelectedIndex + 1, Convert.ToInt32(Day.Value)) 'If Month, Day, or Year not selected then
I need to download serveral years worth of files from a web site, the web site posts files daily in "Date".csv. How do I write the code in vb.net to get the string value for the dates? I know that you can do something like : Dim start date = #11/01/2009# and Dim end date= Now.
How do I get these values so I can incorportate them in a string? And then loop through each value.
It will need to start with the first date an download that file, then loop through all the dates downloading each file until it has reached the end date. I already have the code written to extract the info i need from the document and import into a sql server, my only issue is the date range string issue
program that allows the user to enter a month and a number of years. (e.g March and 10 years) The program then displays all the months of the year from the entered month in a loop that runs as many times as the number of years.(e.g March April May.....December January February March....)
Two quick questions about datagridviews... I have an unbound dgv and I'm trying to do some simple formatting but sadly my .net knowledge is limited at best. I'm trying to make a balance sheet and I need to do two things:
1. How can I set row(d) to sum row(a:c) for each column (for multiple years of financials)
2. Is there anyway to not only make a row readonly, but make in unselectable (to skip totaled rows)?