-2

l'm having a problem with the date function turning every date of mine into a string, can someone show me how to concatinate the dates together without turning the date into a string, this is my code:

 var date = new Date();
 var day = date.getDate();
 var month = date.getMonth();
 var year = date.getFullYear();
 console.log(day + '/' + month + '/' + year);

and this is my result: "23/5/2016"

but the answer l am looking for is this: 23/5/2016

could someone please help.

  • Possible duplicate of [Converting string to date in js](http://stackoverflow.com/questions/5619202/converting-string-to-date-in-js) – Vucko Jun 23 '16 at 07:53
  • What difference does it make? Obviously you are creating a string and thus getting a string. – Mohit Bhardwaj Jun 23 '16 at 07:54
  • A formatted date is by definition a string. Your result string does *not* have quotation marks within the string. – nnnnnn Jun 23 '16 at 07:57
  • new Date() is a date object that has properties and methods. If you manipulate with it you get string(array of characters) or same date object with different value. You cannot have formatted date that is date object. – natchkebiailia Jun 23 '16 at 07:58

1 Answers1

0

your code is just fine, the way you like it, I presume you are just a little bit confused. This code literally give the expected result alert(). like this

 var date = new Date();
 var day = date.getDate();
 var month = date.getMonth();
 var year = date.getFullYear();
 document.write(day + '/' + month + '/' + year);
Dhia
  • 10,119
  • 11
  • 58
  • 69
pedroyanky
  • 323
  • 2
  • 10