0

Is it possible convert a date value from datepicker into words ?, I know there have been several similar questions here, but I want to do a different approach.

Now I'm trying to use alert to find out the value of the variable before the format changed to words, then there is error message about the index number in the array. it said :uncaught SyntaxError : unexpected Number which is this line bulan 1 januari

is there any advice, to give value to key in the array ?

$( function() {
$( "#pickyDate" ).datepicker({format: "dd/mm/yyyy"});

local = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu' ];
bulan = [1=>'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni','Juli','Agustus','September','Oktober','November','Desember' ];

$('#getdate').datepicker()
.on("change", function () {    

 var today = new Date($('#getdate').datepicker('getDate'));
 var tanggal = today.getDate();
 var no_hari = today.getDay();
 var no_bulan = today.getMonth()+1; 
 var tahun = today.getFullYear(); 
   
   //alert(local[today.getDay()]);
 alert(tahun);
   //$('#wordsdate').val(local[today.getDay()]);


});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>

<div class="form-group">
  <input type="text" class="form-control" placeholder="choose date" id="getdate" />
</div>

  <div class="form-group">
  <input type="hidden" class="form-control" placeholder="datepicker date" id="datenum" disabled/>
  </div>

  <div class="form-group">
  <input type="text" class="form-control" placeholder="wordsdate" id="wordsdate" disabled/>
  </div>

example :
let say we choose a date : 05/06/2014
then result on textfield : the fifth of June Two thousand and fourteen

ariowishnu
  • 35
  • 1
  • 8

2 Answers2

1

You can get this way using Jquery Date Picker, You can select the last option in dropdown

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Format date</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#datepicker" ).datepicker();
    $( "#format" ).on( "change", function() {
      $( "#datepicker" ).datepicker( "option", "dateFormat", $( this ).val() );
    });
  } );
  </script>
</head>
<body>
 
<p>Date: <input type="text" id="datepicker" size="30"></p>
 
<p>Format options:<br>
  <select id="format">
    <option value="mm/dd/yy">Default - mm/dd/yy</option>
    <option value="yy-mm-dd">ISO 8601 - yy-mm-dd</option>
    <option value="d M, y">Short - d M, y</option>
    <option value="d MM, y">Medium - d MM, y</option>
    <option value="DD, d MM, yy">Full - DD, d MM, yy</option>
    <option value="&apos;day&apos; d &apos;of&apos; MM &apos;in the year&apos; yy">With text - 'day' d 'of' MM 'in the year' yy</option>
  </select>
</p>
 
 
</body>
</html>
Mahesh G
  • 1,226
  • 4
  • 30
  • 57
0

Use Capital letters.

You have written dd/mm/yyyy, instead write DD/MM/YYYY

mplungjan
  • 169,008
  • 28
  • 173
  • 236