Potentially easily solvable question-Help needed! Date/Time Picker

nem33

Newcomer
Joined
Mar 17, 2003
Messages
23
Hello,
Im writing a project that requires the user to select a time using the date/time picker. After the user selects a time that he/she had last done something I want to get that time (DateTimePicker1.Value) and then figure out how many---(days, hours, minutes, seconds) it has been since the time they selected. So if they selected "Sunday, March 16th, 2003 11:19AM" It would say ..."1 day, 0 hours, 0 mins, 0 seconds" ..
It's been a while since Ive coded anything and I'm really trying to get the hang of it all again. Any help I might recieve is greatly appreciated. Thanks.
 
You can do this by subtracting the date returned by the control from the date now:

Visual Basic:
Dim ts As TimeSpan = DateTime.op_Subtraction(DateTime.Now, DateTimePicker1.Value)

C#:
TimeSpan ts = DateTime.Now - DateTimePicker1.Value;
 
Excellent--I did this...

Visual Basic:
 Dim ts As TimeSpan = DateTime.op_Subtraction(DateTime.Now, DateTimePicker1.Value)
        Forms.frm1.Label12.Text = System.Convert.ToString(ts)
Works great Thank you
 
One last question---The Time returned is always the time of day equal to vurrent system time--How does the user select a time of day as well as a day on the date/time picker? Can both date and time be selected with one date/time picker? I figured out you could select format to time but that seems to take away the 'date' part of it. Any ideas? Thanks again. =)
 
Visual Basic:
Public Sub SetMyCustomFormat()
    ' Set the Format type and the CustomFormat string.
    dateTimePicker1.Format = DateTimePickerFormat.Custom
    dateTimePicker1.CustomFormat = "yyyy-M-d:H:m"
End Sub 'SetMyCustomFormat


Note The Format property must be set to DateTimePickerFormat.Custom for this property to affect the formatting of the displayed date/time.
 
Back
Top