Need help with a Formula. database to Date

Troy

Well-known member
Joined
Feb 7, 2005
Messages
153
Programming Experience
10+
I need to show the age of something in my database.

I have a variable txtDOM.Value which has the date it was manufactured stored in it.

I need to take that info and subtact it from the current date which is Date.Now. But VB won't let me use that information in mathmatical proceedures.

How can I convert them so that I can do the Math and get my Unit Age?:confused:

I'm actually needing to convert it all into days and get the Number of days old it is.
 
simple approx value

VB.NET:
[/COLOR][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dtNewDate [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE]
[SIZE=2]dtNewDate = [/SIZE][SIZE=2][COLOR=#0000ff]CDate[/COLOR][/SIZE][SIZE=2](TextBox2.Text)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] iDays [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2]iDays = (Now.Date.Subtract(dtNewDate)).Days[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] iYears [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32 = Math.Floor(iDays / 365)[/SIZE]
[SIZE=2]iDays = iDays [/SIZE][SIZE=2][COLOR=#0000ff]Mod[/COLOR][/SIZE][SIZE=2] 365[/SIZE]
(iYears,iDays)

this gives u the approximate age in years,days . assuming all years are 365 days.. if u really need the precession to the quarter day of every year let me know i will post that ..
-gkopparam
 
Last edited by a moderator:
Ok I don't think thats exactly what I'm looking for. I need for example,

This model house was built 11/03/1995 and it sold 8/12/1997. I need to know how many days it spend on my lot. from 11/03/1995 to 8/12/1997.
 
my post is update

VB.NET:
[COLOR=#0000ff]Dim[/COLOR][SIZE=2] dtOldDate [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dtNewDate [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE]
[SIZE=2]dtOldDate = [/SIZE][SIZE=2][COLOR=#0000ff]CDate[/COLOR][/SIZE][SIZE=2](TextBox1.Text)[/SIZE]
[SIZE=2]dtNewDate = [/SIZE][SIZE=2][COLOR=#0000ff]CDate[/COLOR][/SIZE][SIZE=2](TextBox2.Text)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] iDays [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Int32[/SIZE]
[SIZE=2]iDays = (dtNewDate.Subtract(dtOldDate)).Days[/SIZE]
 
Last edited by a moderator:
OK sweet thats what I was looking for! Thanks!
 
Back
Top