1

Im using ionicframework to build hybrid app with angular. im having a form with two input box : date and time. The value of date input is saved in the database as: Tue Mar 24 2015 00:00:00 GMT 0300 (AST) i get this type of data when running the form on my android device, but i want to save the date as simple like: 24-04-2015

What i tried

form.html

<form>
<input ng-model="app.date" class="positive" type="date">
<input ng-model="app.time" class="positive" type="time">
<button ng-click="makeApp(app)">send</button>
</form>

controller.js

$scope.makeApp = function (app) {
$http.post("http://www.foo.com/senddata.php?date="+app.date+"&time="+app.time)
.success(function(data){   
});

1 Answer 1

5

You can use Angular's date filter:

myApp.controller('MyController', ['$scope', '$http', '$filter', function ($scope, $http, $filter) {

    $scope.makeApp = function (app) {

        var appDate = $filter('date')(app.date, "dd/MM/yyyy");
        $http.post("http://www.foo.com/senddata.php?date="+appDate+"&time="+app.time)
            .success(function(data){   
                // success
            });
    }
}

https://docs.angularjs.org/api/ng/filter/date

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.