0

I have date picker, i want to convert date format to '2014/12/03(i.e yyyy/mm/dd)'.

date format is dd/mm/yyyy in the text field, while focusout need to change the date format to yyyy/mm/dd(passing the date value to server)

<div for="dtp_input2" class="input-group date form_date"  data-date-format="dd/mm/yyyy" data-link-field="dtp_input2" data-link-format="dd/mm/yyyy" data-ng-model="systemdate"  date-picker>
   <input type="text" id="systemdate" name="systemdate" class="form-control input-append inputDatepicker"  placeholder="Date" data-ng-model="systemdate" data-ng-blur="getBatchNumbers()" format-date/>
    <span class="input-group-addon">
         <span class="glyphicon glyphicon-calendar add-on"></span>
    </span>
</div>
<input type="hidden" id="dtp_input2" value="" />

I tried to convert inside controller,

console.log($scope.systemdate); //2014-03-12
var date = $filter('date')($scope.systemdate, "yyyy-MM-dd");

but 'date' variable also converting in same format i.e 2014-03-12

4
  • 1
    Try this: var date = $filter('date')($scope.systemdate, "yyyy/MM/dd"); Commented Feb 13, 2015 at 7:00
  • 1
    You can momentJS lib for it. Commented Feb 13, 2015 at 7:42
  • Could you elaborate on the date picker ? How does it set the systemdate? From your html snippiet it looks like you are setting systemdate with an input element + ng-model.? For a simple approach of formatting the input text as a date, see github.com/betsol/angular-input-date Commented Feb 13, 2015 at 9:29
  • Also, look here for a nice solution on how to wrap a datepicker in an AngularJS directive: stackoverflow.com/questions/22728585/… (while taking care of date format) Commented Feb 13, 2015 at 12:04

1 Answer 1

0

Please have a look at the below link

http://plnkr.co/edit/J6ATK1ozJFxZQFSXaUNy?p=preview

HTML

Enter Date : <input type="text" placeholder='dd/mm/yyyy' onblur='changeFormat()' id='ipdate'/>

JS

var changeFormat = function (ipdate) {
  var d = document.getElementById('ipdate').value;
  d = d.split("/");
  d.reverse();
  document.getElementById('formattedDate').innerHTML = d[0]+'/'+d[1]+'/'+d[2];
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.