Hi
In alert it is showing 16-10-22 but it is giving message Invalid Date
JavaScript
function DoValidation(parameter) {
var valid = true;
var txtRemark = document.getElementById("txtRemarks").value;
var ddlStatus = "";
if (document.getElementById('ddlStatus')) {
var ddlStatus0 = document.getElementById("ddlStatus");
ddlStatus = ddlStatus0.value;
}
var theDate = document.getElementById("txtReceivedOn").value;
alert(theDate);
if (ddlStatus == "Return Delivered" && (theDate.trim() === "" || isNaN(new Date(theDate).getTime()))) {
bootbox.alert({
size: 'small',
title: 'Error!',
message: 'Invalid Date'
});
valid = false;
}
return valid;
};Thanks

Vishal JoshiRank #377 · 6.7K reputationPosted Oct 14, 2022, 8:58 AM EDT
Hello
You need to convert to datetime before pass to new Date() please check below code
CultureInfo provider = CultureInfo.InvariantCulture; DateTime dateTime = DateTime.ParseExact("16-10-22", "dd-mm-yy", provider);Sachin SinghRank #66 · 26.2K reputationPosted Oct 15, 2022, 4:35 PM EDT
16-10-22 is an invalid date format from JS perspective. Such format will always give you invalid date format.
You need to parse it in yyyy-mm-dd format first before passing it to new Date() method.
var date1=new Date().getFullYear()+"-"+theDate.split("-")[1]+"-"+theDate.split("-")[0]; if (ddlStatus == "Return Delivered" && (theDate.trim() === "" || isNaN(new Date(date1).getTime()))) { bootbox.alert({ size: 'small', title: 'Error!', message: 'Invalid Date' }); valid = false; }