-2

Actually my problem is that i have to retrieve data in 'dd-MM-yy' format but whenever i try to change 'dateFormat' attribute to 'dd-MM-yy'format,I haven't process further. so please help me to find the solution of this issue..

 $("input[name='plannedPrgomStartDate']").datepicker({
                                showOn: "button",
                                buttonImage: "../../IMAGES/EQM/calender_icon.png",
                                buttonImageOnly: true,
                                changeYear: true,
                                changeMonth: true,
                                yearRange: yrRange,
                                dateFormat: 'MM-dd-yy',

                            });

$("input[name='plannedPrgomEndDate']").datepicker({
                                showOn: "button",
                                buttonImage: "../../IMAGES/EQM/calender_icon.png",
                                buttonImageOnly: true,
                                changeYear: true,
                                changeMonth: true,
                                yearRange: yrRange,
                                dateFormat: 'MM-dd-yy',

                            });

Here is my code for getting the date value

var plannedPrgomStartDate = $('#plannedPrgomStartDate').datepicker().val();
                        var plannedPrgomEndDate = $('#plannedPrgomEndDate').datepicker().val();                        
                        if (Date.parse(plannedPrgomStartDate) >= Date.parse(plannedPrgomEndDate)) {
                            displayErrorFeedback("Start date can not be greater than or equal to end date.");
                                loaderHideShow();
                                 return false;
                        }
wasim ali
  • 39
  • 1
  • 10

1 Answers1

0

Multiple problems here... :


First, you access the same component (it's the same, right ?) differently. First time with name $("input[name='plannedPrgomStartDate']") Second time with id $('#plannedPrgomStartDate') So check it's not a mistake and you really have same name and id.

Then, as you get the date value at the datepicker init, you should get no value because none is selected... So Date.parse('') will give you NaN.

Or if the first code part is executed before, you're datepicker is already initialized. So why do you init it again with : $('#plannedPrgomStartDate').datepicker().val(); ?

$('#plannedPrgomStartDate').val(); should be suficient.

When this is ok, it should not be a problem with the date format. It should work as expected. See : https://jsfiddle.net/1cym5p6s/

ylerjen
  • 4,109
  • 2
  • 25
  • 43