0

I'm not sure how I will do it, I want to convert a date into English word format, like this, if the date is 10-10-1988 then

In English: tenth October nineteen eighty-eight

Please Help Me

Fiddle Here

Mohsen Alyafei
  • 4,765
  • 3
  • 30
  • 42
user3136255
  • 149
  • 4
  • 12
  • Your fiddle doesn't show any research effort. What did you try yourself? – Michał Mar 20 '14 at 07:07
  • possible duplicate of [Get month name from Date](http://stackoverflow.com/questions/1643320/get-month-name-from-date) – Michał Mar 20 '14 at 07:09
  • Or this one: http://stackoverflow.com/questions/2974496/jquery-javascript-convert-date-string-to-date – Pavlo Mar 20 '14 at 07:10
  • @Michał: Both Question are different from my question – S. S. Rawat Mar 20 '14 at 07:12
  • No, they are almost the same. Just need to create more arrays – Michał Mar 20 '14 at 07:14
  • this is what you want,but its using c#,try to implement same logic using javascript http://stackoverflow.com/questions/10565815/how-to-convert-date-to-word-format – Cris Mar 20 '14 at 07:14
  • Here is your answer! http://stackoverflow.com/questions/7151543/convert-dd-mm-yyyy-string-to-date `from = $("#datepicker").val().split("-"); f = new Date(from[2], from[1] - 1, from[0]);` – Pavlo Mar 20 '14 at 07:14

5 Answers5

1

Something like that

var wDays = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', ' seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth', 'thirteenth', 'fourteenth', 'fifteenth', 'sixteenth', 'seventeenth', 'eighteenth', 'nineteenth', 'twentieth', 'twenty-first', 'twenty-second', 'twenty-third', 'twenty-fourth', 'twenty-fifth', 'twenty-sixth', 'twenty-seventh', 'twenty-eighth', 'twenty-ninth', 'thirtieth', 'thirty-first']

var wMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
var wNumbers = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twentyone']

var date = new Date()
var day = parseInt(date.getUTCDate()) - 1;
var month = parseInt(date.getUTCMonth());
var year = date.getUTCFullYear().toString();

var x = year.charAt(0)
var xx = year.charAt(1)
var xxx = year.charAt(2)
var xxxx = year.charAt(3)


var a = parseInt(x + xx) - 1
var b = parseInt(xxx) - 1
var c = parseInt(xxxx) - 1
console.log(wDays[day] + ' ' + wMonths[month] + ' ' + wNumbers[a] + ' ' + wNumbers[b] + ' ' + wNumbers[c])
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Devima
  • 1,566
  • 2
  • 10
  • 16
1

With credits to an article on About.com, I figured out a perfect solution to this question.

The above reference helped me parse the Numerals in date to Words, while I tweaked it a little for helping me with Months.

var stu = $("#txtStartDate").val().split('-');
var wMonths=['january','february','march','april','may','june','july','august','september','october','november','december']
var final  = toWords(stu[0]) + " " + wMonths[parseInt(stu[1])-1] + " " + toWords(stu[2])   
alert(final);

function toWords(s)
{
    // Open Fiddle for complete code
    // convert number to words
}

Follow this Fiddle for the complete code. Hope this helps someone.

Cyberpks
  • 1,401
  • 6
  • 21
  • 51
0

Use Date JS or also you can use Jquery UI date picker.

Jquery UI Date Picker

Nidhin S G
  • 1,685
  • 2
  • 15
  • 45
0

You can refer dobToWords angular library for angular application which can help you out in converting the date object into the words.

For Example: For date 21-4-1990 it will convert the date into words and will give you output as "Twenty-First April Nineteen Ninety"

    angular.module('sampleApp',[dobToWords])
   .controller('SampleCtrl',['$scope','convertDobToWords',function($scope,convertDobToWords){
        var dateOfBirth = new Date('04/21/1990');
        var dobIntoWords = convertDobToWords.convertIntoWords(dateOfBirth);
        console.log('Date of Birth in Words : '+ dobIntoWords);
     }]);
0

You could try something like this:

var dateTime = new Date($("#selector").datepicker("getDate"));
var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var date = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth', 'thirteenth', 'fourteenth', 'fifteenth', 'sixteenth', 'seventeenth', 'eighteenth', 'nineteenth', 'twentieth', 'twenty-first', 'twenty-second', 'twenty-third', 'twenty-fourth', 'twenty-fifth', 'twenty-sixth', 'twenty-seventh', 'twenty-eighth', 'twenty-ninth', 'thirtieth', 'thirty-first'];
var strDateTime =  "Day " + date[dateTime.getDate()-1] + " of " + month[dateTime.getMonth()] + " in the year " +  toWords(dateTime.getFullYear());
console.log(strDateTime);

function toWords(s){
    var th = ['','thousand','million', 'billion','trillion'];
    var dg = ['zero','one','two','three','four', 'five','six','seven','eight','nine'];
    var tn = ['ten','eleven','twelve','thirteen', 'fourteen','fifteen','sixteen', 'seventeen','eighteen','nineteen'];
    var tw = ['twenty','thirty','forty','fifty', 'sixty','seventy','eighty','ninety'];
    s = s.toString();
    s = s.replace(/[\, ]/g,'');
    if (s != parseFloat(s)) {
        return 'not a number';
    }
    var x = s.indexOf('.');
    if (x == -1) x = s.length;
    if (x > 15) return 'too big';
    var n = s.split('');
    var str = '';
    var sk = 0;
    for (var i=0; i < x; i++) {
        if ((x-i)%3==2) {
            if (n[i] == '1') {
                str += tn[Number(n[i+1])] + ' ';
                i++;
                sk=1;
            } else if (n[i]!=0) {
                str += tw[n[i]-2] + ' ';
                sk=1;
            }
        } else if (n[i]!=0) {
            str += dg[n[i]] +' ';
            if ((x-i)%3==0) str += 'hundred ';
            sk=1;
        }
        if ((x-i)%3==1) {
            if (sk) str += th[(x-i-1)/3] + ' ';
            sk=0;
        }
    }
    if (x != s.length) {
        var y = s.length;
        str += 'point ';
        for (var i=x+1;    i<y; i++) str += dg[n[i]] +' ';
    }
    return str.replace(/\s+/g,' ');
}
giusti
  • 3,156
  • 3
  • 29
  • 44