I have actually 2 time pickers one is for begin Time and also an additional for End Time, The End Time have to be always higher than start time. I am making use of eonasdan datetimepicker. If start day is better than end day it have to not permit or we need to acquire pop. Please aid me out through this

Here"s what i have done so far




You are watching: Start time must occur earlier than end time

$("#starttime,#endtime").datetimepicker( format: "HH:mm");var start_time = $("#Start_Time").val();var end_time = $("#End_Time").val();if (Date.parse(start_time) > Date.parse(end_time)) alert("begin time have to be smaller");

*

*

feature TimePickerCtrl($) var startTime = $("#starttime").datetimepicker( format: "HH:mm" ); var endTime = $("#endtime").datetimepicker( format: "HH:mm", minDate: startTime.data("DateTimePicker").date() ); feature setMinDate() return endTime .data("DateTimePicker").minDate( startTime.data("DateTimePicker").date() ) ; var bound = false; attribute bindMinEndTimeToStartTime() return bound endTime.on("dp.change", () => bindMinEndTimeToStartTime(); bound = true; setMinDate(); );$(document).ready(TimePickerCtrl);
*

var startDate = Date.parse($("#txtdatetimepicker1").val()); var endDate = Date.parse($("#txtdatetimepicker2").val()); if (startDate >= endDate) alert("Please enter correct date")
*

Disable the past dates than begin day in end_time text box. Something prefer this, please replace textbox id as in your html code.

$( "#startDate" ).datepicker( onSelect: function(dateText, inst) $("#endDate").datepicker("option", "minDate", $(this).val()); , minDate: 0);$( "#endDate" ).datepicker( onSelect: function(dateText, inst) if($( "#startDate" ).val() == "") $( "#endDate" ).val(""); ,)

*

I did some thing with timepicker

Fiddle Link Over here...!

https://fiddle.jshell.net/kxL0f1gc/Try this HTML Code


$(".begin, .end").timepicker( showInputs: false, minuteStep: 1,);$( "#end, #start" ).change(function() {var time = $("#start").val();var hours = Number(time.match(/^(d+)/)<1>);var minutes = Number(time.match(/:(d+)/)<1>);var AMPM = time.match(/s(.*)$/)<1>;if(AMPM == "PM" && hours


See more: Quant Job Interview Questions And Answers (Second Edition), Quant Job Interview Questions & Answers

Set time validation through AM and PM

var startTime = $(".StartTime").datetimepicker( "allowInputToggle": true, "showClose": true, "showClear": true, "showTodayButton": true, "format": " hh:mm A", "useCurrent": false ) var endTime = $(".EndTime").datetimepicker( "allowInputToggle": true, "showClose": true, "showClear": true, "showTodayButton": true, "format": " hh:mm A", "useCurrent": false ) .on("dp.change", function (e) minDate: startTime.data("DateTimePicker").date() bindMinEndTimeToStartTime(startTime); bound = true; setMinDate(endTime,startTime); ); attribute setMinDate(endTime,startTime) rerevolve endTime.data("DateTimePicker").minDate(startTime.data("DateTimePicker").date() ); attribute bindMinEndTimeToStartTime(startTime) var bound = false; return bound