Lara Ch
Lara Ch

Reputation: 165

Transform the number returned from input type month into text

I added an input type=month in my page and I am getting the value using jquery as per example 2017-08. How can I transform it to August, 2017 ?

Upvotes: 0

Views: 92

Answers (3)

Sanjay Kumaar
Sanjay Kumaar

Reputation: 48

try this,

moment('2017-08', 'YYYY-MM').format('MMM, YYYY');

Upvotes: 2

Mehdi
Mehdi

Reputation: 137

You could use moment.js to achieve this:

moment('2017-08', 'YYYY-MM').format('MMMM, YYYY');

Upvotes: 2

Niklesh Raut
Niklesh Raut

Reputation: 34914

You can make a array of month name and use like this

allMonths = ["January", "February", "March","April", "May", "June", "July","August", "September", "October","November", "December"];

var date = new Date("2017-08");
var month = date.getMonth();
var year = date.getFullYear();
console.log(allMonths[month]+", "+year);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Upvotes: 2

Related Questions