Convert A Number Into Equivalent Years And Months?

Dec 23, 2010

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

[Code].....

View 3 Replies


ADVERTISEMENT

C# - A Real Timespan Object With .Years And .Months?

Dec 16, 2009

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!

View 5 Replies

Interval Of Days / Months / Years Between 2 Given Dates

Dec 21, 2011

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!

View 10 Replies

Calculating Exact Time In Years, MOnths, Days?

Jul 22, 2011

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.

View 39 Replies

VS 2010 Find Amount Of Years And Months Between Two Dates?

Jun 29, 2011

I have two dates, a creation date and an expiry date. I want to find out how many years and months (not days unless it is only days) between them.

I've got two dates:

Dim start_time = "12.5.2011"
Dim end_time = "15.11.2014"

I want it to say (3 Years, 6 Months) etc

View 4 Replies

C# - Calculate Difference Between Two Dates In Form `X Years, Y Months, Z Week, A Day`

Jul 10, 2011

How to get difference between two dates in Year/Month/Week/Day?

How do i calculate exact difference between to date including years, days, moths, weeks. Just like windows calculator does. ?

And represent like this 1 years, 1 months, 1 week, 1 day

View 3 Replies

Small Box Which Updates Itself Automatically To Show The Amount Of Years,months,days,hours,minutes And Seconds?

Oct 20, 2010

I have made a new form on vb 2010. I need a small box which updates itself automatically to show the amount of years,months,days,hours,minutes and seconds from the 25/6/09. How would i do this in visual basic 2010?

View 3 Replies

Calculate Number Of Years To Double It?

Apr 28, 2011

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.

View 2 Replies

Convert No Of Months To Date To Calculations?

Jun 5, 2011

Am a student novices in vb.net. But task to vb.net for school project. I want a code to help me add a No fo Months(this is an integer) from date and the result display in a tet box as a date. I have 2 fields: Months and startdate, the third which enddate get focus, the system the enddate. eg 6 months to make a payments, the payment start from 01-02-2011. i want small code which would determine the enddate of the payment period. or the month/year of thee repayment period

View 11 Replies

Program That Allows The User To Enter A Month And A Number Of Years?

Jun 10, 2011

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....)

View 1 Replies

.net - Calculating Number Of Months Between 2 Dates?

Jul 14, 2010

I have the following VB.NET Code:

Dim Date1 As New DateTime(2010,5,6)
Dim Date2 As New DateTime(2009,10,12)
Dim NumOfMonths = 0 ' This is where I am stumped

What I am trying to do is find out how many months are between the 2 dates.

View 3 Replies

Calculate Number Of Months Between Two Dates?

Mar 3, 2011

I have two date values.

Example:

Dim d1 As DateTime = New DateTime(2010, 6,6)
Dim d2 As DateTime = New DateTime(2011, 2,2)

View 3 Replies

Calculate The Number Of Months Between 2 Dates In Vb 2008?

Aug 5, 2009

I am attempting to calculate the number of months between 2 dates in vb 2008. Effectively subtracting a date in the past from the current date and then manipulating it to the number of months between the two.

I have done this in VB 6 previously, but can't seem to do it in vb2008.

View 7 Replies

C# - Function To Calculate Number Of Months Including Current One?

Feb 24, 2011

Datediff calculates the no of months between two dates, Is there any function which lets you to calculate the same thing but also includes the current month. Datediff +1 would give the answer, but just wanted to know if theres any inbuilt method.

View 1 Replies

How To Make Previous Years Balance Become Next Years And So Forth

Apr 20, 2011

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.

View 6 Replies

Get Dates Older Than 3 Months And Less Than 6 Months

May 23, 2012

With Vb.Net, How to get dates older than 3 months and less than 6 months ?

View 3 Replies

Date Method - Calculate The Number Of Years For My Calculate Age Event Handler

Mar 30, 2009

I am trying to calculate the number of years for my calculate age event handler, however i am apparently missing a method or whatnot because im trying to calculate the age , can anyone suggest help on this. I need to subtract years to get my age but when i try the birthdate.Subtract (currentDate) method i get an error about not able to convert from LONG?

So below is what I have.

Private Sub btnCalculateAge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateAge.Click
Dim currentDate As Date
Dim BirthDate As Date
Dim Age As Long

[CODE]

View 7 Replies

VS 2008 Depreciation Loop - Calculate Straight-line Depreciation (cost * 1/n) N Being The Number Of Years To Depreciate

Jul 25, 2010

I have a program where I have to calculate straight-line depreciation (cost * 1/n) n being the number of years to depreciate, and Double-Declining depreciation (cost * 2/n) using user input for year of purchase, cost, and years of depreciation. The output needs to be put into 4 columns in a list box. Year, Value at beginning of year, Amount of depreciation during the year and Total depreciation to the end of the year.

The problem I am having is with my loop. It is not properly calculating. I'm sure I am doing something wrong that is simple, but I can't see it.

Here is my code; the problem areas are bold:

Public Class frmDepreciation

Dim Cost, Life, Year, Depreciation, BegValue, EndValue, Total, Counter As Double
Dim fmtStr As String = "{0,-10}{1,10}{2,17}{3,5}{4,-15}"
Dim fmtStr2 As String = "{0,-10}{1,10}{2,17}{3,15}"

[CODE]....

View 3 Replies

Date Function That Calculates The Date Based On The Number Of Months?

Sep 15, 2009

I am using VB.NET. Is there a date function that calculates the date based on the number of months I have given?

for example, if i say July 2009 and looking for 10 months back, it should return Sept 2008.

View 4 Replies

Convert CAPICOM To .NET Equivalent?

Jan 5, 2011

This is the code from my VB6 app using CAPICOM

[Code]...

but I need to convert the same functionality to VB.NET. Is there an equivalent to get the same values?

View 1 Replies

Asp.net - Convert Characters To Html Equivalent Using .net

Apr 5, 2011

I have a text document that is a roster of licensees. I am looping through this document to create a html table of this data. I've come across names with non standard characters.

This is one of them

Aimeé

I tried running all the inputs through the following function, but when it comes across the above character it doesn't replace it.

Function ReplaceBadCharacters(ByVal input As String) As String
Return input.Replace(Chr(233), "é")
End Function

How can I replace each character with the html equivalent?

EDIT

When I debug the above function it shows the input as Aime[] and not Aimeé.

In Chrome it looks like this Aime�

View 2 Replies

Convert A Short To Binary Equivalent?

Sep 28, 2009

I need to convert a Short to his binary equivalent. For example:Dim x As Short = 20480 And then I need a method to get the binary thingy, which in this case is: 101000000000000

I searched for a answer using google, but I couldn't find a proper explanaition.

View 16 Replies

What Is The Equivalent To Vb6 String(number - Character)

Feb 16, 2009

what is the vb.net equivalent to vb6 String(number,character?

View 3 Replies

SQL Server 2005 - Convert DateTime To Hex Equivalent

Sep 14, 2011

How do I achieve the same in VB.NET which is so easily done in SQL Server.
Select Case(GetDate() as VarBinary(8)) --Gives the Current Time in Hex
How can I create the same string in VB.NET so that I can compare in SQL Server as such -
Select Case When GetDate()=Cast(0X00009F5E00D8DF7C As DateTime) Then 'True' Else 'False' End -- 0X00009F5E00D8DF7C Will be the value I get in VB.NET When I convert it Date.Now() To Hex

View 2 Replies

Wpf - Convert C# ObservableCollection Sample To Dataset Or Equivalent

Feb 23, 2011

I have a C# example that is populating a multiselect combobox. This was from an example found online. It works fine with the static values coming from the observable collection. I want to change this to be database driven from a SQL Server backend, but was having issues. I did get it to populate the combobox, but the selection is acting kind of screwy. Some type of simple query from a Northwind table would suffice such as: "Select CategoryName from Categories".

[Code]...

View 1 Replies

Convert String To Proper Case (strConv Equivalent)?

Jul 30, 2007

To convert a string to proper case what's .NET equivalent of Visual Basic strConv Function?

View 5 Replies

Convert Decimal Number To Binary Number With Fixed Bits?

Oct 29, 2010

I want to convert numbers from 0 to 15 like that

[Code]...

Problem is that when we convert 2 to binary number it gives only 10 in binary, but i want to convert 2 to 4 bit binary number 0010.

View 1 Replies

Convert Days To Months And Days?

Dec 12, 2011

convert days to months and days?

Normal 0
false
false
falseEN-US

[Code]...

View 3 Replies

Convert A Hexadecimal Number To A Decimal Number

May 3, 2011

im having trouble understanding this question for a homework assignment. I need to write the PSEUDOCODE for the following scenario, but i got no idea about how to convert a hexadecimal number to a decimal number..You are required to input a two digit hexadecimal number eg. 3f (digits can be entered separately) and calculate the equivalent decimal number. (note the decimal number will be between 0 and 255) . output the decimal number

View 1 Replies

Convert Hex To Number?

Apr 10, 2011

i got hex number from scale weight example:"90 00 00 01 34 = 180 kg" or "90 00 03 03 7c=49670 kg"how to convert hex to number(integer)

View 8 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved