The date picker format stopped working after I moved the code from the PHTML file to a separate JavaScript file

I was implementing a date picker on one of my pages, and it was working fine. However, after moving my JavaScript files from the PHTML file to a separate JS file, it stopped working and is now picking the wrong format. Can you help me fix it?

Working file that present in the same phtml file

 $('#imported_from_dated').datepicker({
    format: '<?php echo DATE_PICKER_FORMAT; ?>', // format 'yyyy-mm-dd'
 }).on('changeDate', function (e) {
   $('#searchDataForm').formValidation('revalidateField', 'imported_from_dated');
   if ($('#imported_to_dated').val() != '') {
     $('#searchDataForm').formValidation('revalidateField', 'imported_to_dated');
   }
   $('#imported_from_dated').show();   
 });

 $('#imported_to_dated').datepicker({
   format: '<?php echo DATE_PICKER_FORMAT; ?>', // format 'yyyy-mm-dd'
 }).on('changeDate', function (e) {
    $('#searchDataForm').formValidation('revalidateField', 'imported_from_dated');
    $('#searchDataForm').formValidation('revalidateField', 'imported_to_dated');
    $('#imported_to_dated').show();
 });

 $('#searchDataForm').formValidation({
    message: 'list message',
    fields: {
        imported_from_dated: {
            validators: {
                notEmpty: {
                    message: 'error message 1',
                },
                date: {
                    format: '<?php echo DATE_VALIDATION_FORMAT; ?>', // format MM/DD/YYYY
                    message: 'error message 2',
                }
            }
        },
        imported_to_dated: {
            validators: {
                notEmpty: {
                    message: 'error message 3',,
                },
                date: {
                    format: dateValidationFormat,
                    message: 'error message 4',,
                },
                callback: {
                    callback: function (value, validator, $field) {
                        var startDate = $('#imported_from_dated').val();
                        var endDate = $('#imported_to_dated').val();
                        if (startDate !== '' && endDate !== '') {

                            var dateSt = startDate.split('/');
                            var dateEd = endDate.split('/');
                            var StDt = Date.parse(dateSt[2] + '-' + dateSt[0] + '-' + dateSt[1]); //Year, Month, Date
                            var EdDt = Date.parse(dateEd[2] + '-' + dateEd[0] + '-' + dateEd[1]);

                            if (StDt > EdDt) {
                                return {
                                    valid: false,
                                    message: 'error message 5',
                                };
                            }
                        }
                        return true;
                    }
                }
            }
        }
    }
}).on("keyup",'[name="imported_from_dated"]',function() {
    $("#searchDataForm").formValidation('revalidateField', 'imported_from_dated');
}).on("keyup",'[name="imported_to_dated"]',function() {
    $("#searchDataForm").formValidation('revalidateField', 'imported_to_dated');
});

from the above code while i am selecting any date it will update in to MM/DD/YYYY format.
example : 09/05/2024

But i have move the js file in to seperate file and the code looks like this
PHTML file

 <script type="text/javascript">
    var dateFormat = '<?php echo DATE_PICKER_FORMAT; ?>';
    var dateValidationFormat = <?php echo DATE_VALIDATION_FORMAT; ?>;
 </script>

 JS file

 $('#imported_from_dated').datepicker({
   format: dateFormat,
}).on('changeDate', function (e) {
    $('#searchDataForm').formValidation('revalidateField', 'imported_from_dated');
    if ($('#imported_to_dated').val() != '') {
        $('#searchDataForm').formValidation('revalidateField', 'imported_to_dated');
    }
    $('#imported_from_dated').show();
});

$('#imported_to_dated').datepicker({
   format: dateFormat,
}).on('changeDate', function (e) {
    $('#searchDataForm').formValidation('revalidateField', 'imported_from_dated');
    $('#searchDataForm').formValidation('revalidateField', 'imported_to_dated');
    $('#imported_to_dated').show();
});


$('#searchDataForm').formValidation({
    message: 'list message',
    fields: {
        imported_from_dated: {
            validators: {
                notEmpty: {
                    message: 'error message 1',
                },
                date: {
                    format: dateValidationFormat, // format MM/DD/YYYY
                    message: 'error message 2',
                }
            }
        },
        imported_to_dated: {
            validators: {
                notEmpty: {
                    message: 'error message 3',,
                },
                date: {
                    format: dateValidationFormat,
                    message: 'error message 4',,
                },
                callback: {
                    callback: function (value, validator, $field) {
                        var startDate = $('#imported_from_dated').val();
                        var endDate = $('#imported_to_dated').val();
                        if (startDate !== '' && endDate !== '') {

                            var dateSt = startDate.split('/');
                            var dateEd = endDate.split('/');
                            var StDt = Date.parse(dateSt[2] + '-' + dateSt[0] + '-' + dateSt[1]); //Year, Month, Date
                            var EdDt = Date.parse(dateEd[2] + '-' + dateEd[0] + '-' + dateEd[1]);

                            if (StDt > EdDt) {
                                return {
                                    valid: false,
                                    message: 'error message 5',
                                };
                            }
                        }
                        return true;
                    }
                }
            }
        }
    }
}).on("keyup",'[name="imported_from_dated"]',function() {
    $("#searchDataForm").formValidation('revalidateField', 'imported_from_dated');
}).on("keyup",'[name="imported_to_dated"]',function() {
    $("#searchDataForm").formValidation('revalidateField', 'imported_to_dated');
});

I have verified that the values are being passed to the JS file correctly, but I’m still getting the date in the ‘2024-09-05’ format (not converting to MM/DD/YYYY format). I can’t figure out what’s causing the issue, even though the code inside the JS file is written within the document.ready function.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật