Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert date to words in HTML

I have a date displayed in HTML. The date is currently displayed as 2012-03-12. So now, I want to display this date as words i.e it should be displayed as 12 March 2012. Below is the HTML code I used.

<tr>
  <th>Date of Birth: </th>
  <td>{{dob}}</td>
</tr>  

Here, dob contains the value that has to be converted to words. How can I do this?

like image 779
user3004356 Avatar asked Dec 07 '13 06:12

user3004356


People also ask

How do you change a date to text?

Select all of the dates you want to convert and press Ctrl+C to copy them. Open Notepad or any other text editor, and paste the copied dates there. Notepad automatically converts the dates to the text format. Press Ctrl+A to select all text strings, and then Ctrl+C to copy them.

How do I change the date format in HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

How do I convert numbers to word in HTML?

var words = toWords(num); To get a number converted to words you just need to call the function passing it the number you want to convert and the corresponding words will be returned.

How do I convert a date to a character?

You can use the as. Date( ) function to convert character data to dates. The format is as. Date(x, "format"), where x is the character data and format gives the appropriate format.


2 Answers

Absolutely with the wonderful MomentJS.

dob = moment(dob).format('DD MMMM YYYY');
like image 123
CWSpear Avatar answered Oct 04 '22 14:10

CWSpear


If your date is an instance of Datethen you can try something like this

var dob = new Date('3/12/2012');
var dobArr = dob.toDateString().split(' ');
var dobFormat = dobArr[2] + ' ' + dobArr[1] + ' ' + dobArr[3];

This would make dobFormat 12 Mar 2012 (if you want it to say March couple this with what Rhyono has suggested).

like image 43
tewathia Avatar answered Oct 04 '22 16:10

tewathia