0

I have a form which allows the user to edit an employees clock in and out times. When the employee clocks in or out, it just grabs DateTime.Now and inserts that. This value comes with the 'seconds'.

Is there a way to get the <InputDate> to not show the seconds for picking a date and time? Trying to submit with seconds also causes a pop up message to the user. You must make seconds 00 to be able to submit. I do not need seconds as an option for the user to input at all.

In the code below I have trid adding @bind-Value:format="mm/dd/yyyy hh:mm tt" to the clock in InputDate but it does not get rid of the seconds choice. I late found that adding step="any" will solve this issue of submitting, however, I simply don't want the seconds to be an option to pick.

                    <div class="col-md-6">
                        <label>Clock In: </label> 
                        <InputDate Type="InputDateType.DateTimeLocal" class="form-control" id="ClockIn" @bind-Value="employeeclockTime.ClockIn" @bind-Value:format="mm/dd/yyyy hh:mm tt" placeholder="Clock In" />
                              
                    </div>
                    <div class="col-md-6 mt-5 mt-md-0">   
                         <label>Clock Out: </label>
                         <InputDate Type="InputDateType.DateTimeLocal" class="form-control" id="ClockOut" @bind-Value="employeeclockTime.ClockOut" placeholder="Clock Out" />
                    </div>

enter image description here

enter image description here

Aakburns
  • 307
  • 1
  • 5
  • 19
  • I copied your code and initialised the time with `DateTime.Now` it did not replicate the problem. Was this specific to a particular browser? – Brian Parker Jul 13 '22 at 21:08
  • If the datetime exists already and has seconds, it will show the seconds in the picker, which I don't want to see. – Aakburns Jul 13 '22 at 21:30
  • I was using `public DateTime ClockIn { get; set; } = DateTime.Now;` in my class so the seconds existed! – Brian Parker Jul 13 '22 at 21:54
  • Did the datetime picker, show a seconds input when editing this value? – Aakburns Jul 13 '22 at 21:55
  • No it did not. I checked in the debugger the property had a seconds value. – Brian Parker Jul 13 '22 at 21:55
  • I am using 6.0.7 in my test. I tested on Chrome Edge and Firefox – Brian Parker Jul 13 '22 at 21:57
  • I tried it the way you did with 'public DateTime ClockIn { get; set; } = DateTime.Now;' I get back 07/13/2022 04:56:55pm when I open the datetime picker it has a hours/minutes/seconds in the picker. If the datetime 07/13/2022 04:56:00pm where seconds is 00 the seconds option in the picker is gone. I'm not sure why you're just getting the option for hours/minutes in the picker. – Aakburns Jul 13 '22 at 21:58
  • Version 6.0.1 here. – Aakburns Jul 13 '22 at 22:06
  • This probably has your answer: https://stackoverflow.com/questions/31578289/strip-seconds-from-datetime – Joe Jul 19 '22 at 20:23

0 Answers0