Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff help

Status
Not open for further replies.

JackBurton07

IS-IT--Management
Oct 17, 2007
75
GB
I need to calculate the difference between today's date and
23/06/2017(which is txtterm1.value) ands display it in a text box (txtmat1.text)
I heard that DateDiff is supposed to do this but cant figure it out

does this look right?

Function calculate_days()

txtMat1.Text = DateDiff(DateInterval.Day, txtterm1.Value, Now)
Return txtMat1.Text
End Function
 
Hi,

I would write the code as follows:

Function calculate_days(DateFrom As Date, DateTo As Date) As Integer
Dim ans As Integer

ans = DateDiff(DateInterval.Day, DateFrom, DateTo)

Return ans
End Function

Then in the main code, I would use:

txtMat1.Text = calculate_days(Date.Parse(txtterm1.Value), Now)


Is txtterm1 a textbox?

 
Public Sub calculate_days(DateFrom As Date, DateTo As Date)

txtMat1.Text = DateDiff(DateInterval.Day, DateFrom, DateTo)

End Sub

Or:

Public Sub calculate_days()

txtMat1.Text = DateDiff(DateInterval.Day, Date.Parse(txtterm1.Value), Now)

End Sub


If txtterm1 is a textbox you should use txtterm1.Text to reference the value of the textbox.

I hope this helps
 
Hi

The txtTerm1.Value keeps getting highlighted with Error 'Value' is not a member of 'System.Windows.Forms.TextBox'.

sorry - im new to VB and dont know how to reference it

Thank you for your help - it is much appreciated
 
use txtTerm1.Text



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top