Click here to Skip to main content
15,746,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On edit of angular form I am getting date in other than "MM/dd/yyyy" format. Below are the view and angular controller. The date is coming with time zone.

<input id="dob" type="text" class="form-control myCalendar" ng-model="employeeDOB" data-modal="modal" ng-required="true" datepicker filter="date" />

Angular Module:
var app = angular.module("myApp", ['angularUtils.directives.dirPagination']);    
    app.directive('datepicker', function () {
        return {
            require: 'ngModel',
            link: function (scope, element, attrs, ngModelCtrl) {         
                    mask: true,              
                    timepicker: false,
                    format: 'm/d/Y',             
                    onSelect: function (dateText, inst) {
                    }).on('blur', function () {    

What I have tried:

$scope.employeeDOB = new Date(employee.DOB);
$scope.employeeDOB = new Date(\d+/)[0] * 1);
Updated 22-Jun-16 1:07am

try this
var d =new Date(employee.DOB);
       var datestring =("0"+(d.getMonth()+1)).slice(-2) +"/" +  ("0" + d.getDate()).slice(-2) + "/" +   + d.getFullYear();
       $scope.employeeDOB = datestring;
Share this answer
Sunil bamal 23-Jun-16 2:25am    
Since i have changed my angular file to a newer version and after using input=date now m getting value in yyyy-mm-dd. So may be now your solution need to be change a bit.
Karthik_Mahalingam 23-Jun-16 2:27am    
var d =new Date(employee.DOB);
var datestring =d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) +"-" + ("0" + d.getDate()).slice(-2) ;
$scope.employeeDOB = datestring;
Sunil bamal 23-Jun-16 2:30am    
now after changing back to input="text" is working.., thanks @Karthik
Karthik_Mahalingam 23-Jun-16 2:31am    
welcome :)
Sunil bamal 23-Jun-16 2:51am    
@Karthik, I have to clear cache manually in every browser to get reflection of changes in angular file, do have any idea why it happen and is there any solution to get reflection in browser without clearing cahe manually??
1. Can you try "MM/dd/yyyy" for the format instead of using 'm/d/Y'?
2. If that doesn't work, what do you want to do with employeeDOB, just displaying it on the page or store in a DB? If just display, you can try {{employeeDOB | date:'MM/dd/yyyy'}}.
Share this answer
Sunil bamal 23-Jun-16 2:17am    
no i cant change m/d/Y to MM/dd/yyyy it will change date in some other format which is a invalid date format. And i am trying with ng-model in input so i cant use {{employeeDOB | date:'MM/dd/yyyy'}} as well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900