Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 11, 2011 7:32 AM
I have a time span value of 9:00:00, now I want to display this in the datetimepicker control using its value property so when I click the spin button, the value property will update its value.
The more I study, the more I realize how little I know.
All replies (5)
Tuesday, January 11, 2011 9:06 AM ✅Answered | 1 vote
hi,
i have no idea why you want to display timespan as datetime, but please visit similar thread http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/20304b8c-1e2d-4130-86ba-6c30f5ee6175/ for more info. when you convert timespan to datetime, you can attach it into datetimepicker.value property:
DateTime dt = new DateTime(0),
dt.Add(mytimespan);
but maybe you want something like this:
DateTime now = DateTime.Now;
DateTime newTime = now.Add(mytimespan);
BR, Karol. mark as answer/vote as helpful if it helped you
Thursday, January 13, 2011 6:43 AM ✅Answered
Hi Sheen Ismhael Lim:
Welcome you to the MSDN Forum.
Based on your description, When you click the spin button, you can use the following method to change the value of your DatetimePicker:
DateTimePicker1.Value = DateTime.Now.Add(/* your TimeSpan */);
I hope it is helpful to you.
If you have any concerns, please feel free to tell us.
Best Regards
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the C# Forum! If you have any feedback, please tell us.
Tuesday, January 11, 2011 9:13 AM
I have a 3rd party control (a week scheduler) which one of its property accepts or returns time span value. I want to display the time span value so that the user have the flexibility to adjust the value as he/she see fit.
The more I study, the more I realize how little I know.
Tuesday, January 11, 2011 9:25 AM | 1 vote
so you can do it with datetimepicker when you set dispaly format to: HH:mm:ss +attach value as a datetime with any day but with good time (to day with time 00:00:00 add your timespan)
if not you have to write your own control
BR, Karol. mark as answer/vote as helpful if it helped you
Wednesday, January 20, 2016 1:08 PM
DateTimePicker1.Value = DateTime.Now.Date.Add(/* your TimeSpan */);is the Current Answer as the code belowDateTimePicker1.Value = DateTime.Now.Add(/* your TimeSpan */);
will add the Now Time to your timespan.
Thanks
Web Developer 4.0