Search code examples
phpjavascriptpyrocms

How to replace string with single quotes?


My Date value is 2013/06/04 - 2013/06/06 , i want to replace it with '2013/06/04' And '2013/06/06' how can i do it? I tried giving

var value = $("#date_range").val().replace('-','\''); 

but i am getting escape character?


Solution

  • Your attempt wouldn't wrap the outer sides of the dates in quotes anyway, so I don't think that's what you're looking for. Try:

    var str = "2013/06/04 - 2013/06/06";
    var dates = str.split(" - ");
    var value = "'"+dates.join("' and '")+"'";
    

    JSFiddle

    Results in '2013/06/04' and '2013/06/06'