Concatenate single quotation marks in date variable?

0

I have an application in VueJS and I need to concatenate simple quotes in a variable that has a date like this 2017-11-09T02:00:00.000Z .

I tried the following and I did not succeed:

var novaData = "'" + data + "'"

I tried to use the same methodology on the server, but it returns the following result:

'\'2017-11-02T02:00:00.000Z\''

And for nothing in this world I could not do replace() of \

What I need is that after concatenating the returning string looks like this:

'2017-11-02T02:00:00.000Z'

I need the date in this format to query MongoDB.

If someone can help me, I thank them ...

    
asked by anonymous 09.11.2017 / 14:28

3 answers

1

You can send with JSON.stringify , which creates a string with quotation marks inside the string:

var date = new Date();
var string = JSON.stringify(date);
console.log(typeof string, string); // string "2017-11-09T14:12:21.523Z"
    
09.11.2017 / 15:12
2

You can redraw the date string with toISOString :

let dt = new Date();
console.log(typeof dt.toISOString(), dt.toISOString());
    
09.11.2017 / 14:34
0

Question:

Concatenate single quotation marks in date variable? '2017-11-02T02:00:00.000Z'

var date = new Date();

var novaData = "'"+date.toISOString()+"'";

console.log(novaData);
    
09.11.2017 / 17:56