trx trx - 1 year ago 65
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
.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 Source

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];
    //Handle error

Hope i've helped you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download