nem33 Posted March 17, 2003 Posted March 17, 2003 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. Quote
*Gurus* divil Posted March 17, 2003 *Gurus* Posted March 17, 2003 You can do this by subtracting the date returned by the control from the date now: Dim ts As TimeSpan = DateTime.op_Subtraction(DateTime.Now, DateTimePicker1.Value) TimeSpan ts = DateTime.Now - DateTimePicker1.Value; Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
nem33 Posted March 17, 2003 Author Posted March 17, 2003 Excellent--I did this... Dim ts As TimeSpan = DateTime.op_Subtraction(DateTime.Now, DateTimePicker1.Value) Forms.frm1.Label12.Text = System.Convert.ToString(ts) Works great Thank you Quote
nem33 Posted March 17, 2003 Author Posted March 17, 2003 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. =) Quote
tonofsteel Posted August 6, 2003 Posted August 6, 2003 Yes how do you select TIME with a DateTimePicker?????? Quote
tonofsteel Posted August 6, 2003 Posted August 6, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.