Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reset the time of datetimepicker in C#

I want to reset the time of a date time picker to 00:00 manually. When i select the date from it i get the time of the instance i select the time is there any way i can reset it to given time?

like image 721
Mobin Avatar asked Jan 24 '23 07:01

Mobin


2 Answers

How about this:

picker.Value = picker.Value.Date;

EDIT: To specify a particular time, you'd use something like:

TimeSpan time = new TimeSpan(3, 30, 0); // 3 hours and 30 minutes
picker.Value = picker.Value.Date + time;
like image 132
Jon Skeet Avatar answered Jan 31 '23 08:01

Jon Skeet


Reset time to 00:00:00

dateTimePicker.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);

Before reset:

2009-08-15 20:27:42

After reset

2009-08-15 00:00:00
like image 23
Michał Ziober Avatar answered Jan 31 '23 10:01

Michał Ziober