Concatenate single quotes into date variable?

Asked

Viewed 1,610 times

0

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

I tried it this way and I didn’t succeed:

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

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

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

And for nothing in this world I couldn’t do the replace() of \

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

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

because I need the date in this format to make queries in Mongodb.

If anyone can help me I’d appreciate it...

  • 1

    Can you explain the original format better? you have a string or an object Date? You’re sending it from Vue to the server?

  • I have an object Date, I apologize for expressing myself badly, and yes, I am sending from the client side to the server

  • Your question is correct Concatenar aspas SIMPLES... or would be `Concatenate quotation marks ...? Just to make sense of the answers

3 answers

2

You can resume the date string with toISOString:

let dt = new Date();
console.log(typeof dt.toISOString(), dt.toISOString());

1


You can send with the JSON.stringify, that creates a quote string inside the string:

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

  • 1

    That’s exactly what I need, it worked perfectly...

0

Question:

Concatenate single quotes into date variable? '2017-11-02T02:00:00.000Z'

var date = new Date();

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

console.log(novaData);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.