trx trx - 29 days ago 8
Javascript Question

Javascript to extract just the date from the variable

I have a variable called

var lastRunDate = encodeURIComponent(trim($("#" + tdLastDateId).text()));


which holds the Date value like
10%2F14%2F2016%2011%3A17%20AM
.Passing them in the URL as a Query Parameter.

var redirect_page = '<%= ResolveUrl("~/GUI/ReviewNEW.aspx") %>' + "?testDate=" + lastRunDate;


I need to extract the just the date without the time before passing them in to the URL. I am not to just extract the Date as omit the Time from it.Any help is greatly appreciated

Answer

in one line you can do that

var decoded = decodeURIComponent( lastRunDate ).split(" ")[0];

But you'd better do something like this

var decoded = decodeURIComponent( lastRunDate );
decoded = decoded.split(" ");
if( decoded.length > 0 ){
    decoded = decoded[0];
}else{
    //Handle error
}

Hope i've helped you