-3

Im trying to get the date, but im wanting to to return ex ”Oct 29”. Ive tryed using split, but it changes everyday. Heres what I have so far.

Let date = Date().split(“ 2021”)[0];

This returns day<string> month day<int>

Monke
  • 23
  • 1
  • 11
  • see: [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – pilchard Oct 29 '21 at 16:13
  • That dosnt exsist It just give an error `Date().getMonth() is not a function` – Monke Oct 29 '21 at 16:18
  • it is a method [Date.prototype.getMonth()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth) but you have to call `new Date()` not `Date()` – pilchard Oct 29 '21 at 16:20

2 Answers2

0

You can format it there are various inbuilt methods or do this:

Let date = Date().toString().substring(4,10);
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
abhi patil
  • 504
  • 2
  • 11
0

You can use the toLocaleString function to achieve what you want. This code below will generate the output you wanted ("Oct 29").

let date = new Date().toLocaleString('en-US', { month: 'short', day: 'numeric' });
LonelyPrincess
  • 461
  • 4
  • 5