VB 2003 programming problem (DateDiff)

Associate
Joined
27 Jun 2003
Posts
526
Location
UK
Anyone know how do get this thing working, been trying for the best part of 2 hours now grrr!! Lost my nerve now.

Basically here is some code I’ve made to work out the difference between the date entered and and current date.

Dim FirstDate, msg as string
Dim SecondDate as string

FirstDate = InputBox(“Enter a date”)

SecondDate = CDate(FirstDate)
Msg = “Days from today: “ & DateDiff(DateInterval.Day, Now, SecondDate)

MessageBox.Show(Msg)

The problem is I have to use a Class to validate data entry, I’ve tried to create on multiple times but it just doesn’t work. The Class has got to receive a string value and returns a date, If the string value received is date in nature then it is converted to a date and returned to the calling code otherwise the current date is returned
 
This is whats in my class now

Friend Function UserDateAsDate(ByVal UserDate As Double) As Double
If IsNumeric(UserDate) Then
UserDateAsDate = UserDate
Else
UserDateAsDate = "Sorry"
End If
End Function

i've changed my form to look like this -->

Private Sub CalculateDaysButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateDaysButton.Click
Dim UserDate As String
Dim Message As String
Dim Validation As New ValidationClass
Dim UserDateisaDate As String


UserDate = NextBirthDateTextBox.Text

UserDateisaDate = Validation.UserDateAsDate(UserDate)

Message = UserDateisaDate

NumberofDaysTextBox.Text = Message

End Sub
 
// Start date
DateTime startDate = new DateTime(2005, 2, 1, 3, 4, 12, 56);
// End date
DateTime endDate = new DateTime(2005, 12, 12, 4, 30, 45, 12);
// Time span
TimeSpan diffDate = endDate.Subtract ( startDate );
// Spit it out
Console.WriteLine( "Time Difference: ");
Console.WriteLine(diffDate.Days.ToString() + " Days");
Console.WriteLine(diffDate.Hours.ToString() + " Hours" );
Console.WriteLine(diffDate.Minutes.ToString() + " Minutes");
Console.WriteLine(diffDate.Seconds.ToString() + " Seconds ");
Console.WriteLine(diffDate.Milliseconds.ToString() + " Milliseconds ");
 
Back
Top Bottom