1
I have the following scenario. A form with two date fields
And when I click search, the data is in this format
How can I get the date in the "yyyy-mm-dd" or "dd-mm-yyyy" format? Without this additional data (Thu Oct, 00:00:00 GMT-0300), someone knows?
Follows my HTML
form name="relatorioPorPeriodo" class="formRelatorio">
<input class="form-control dataini" type="date" name="data_ini" ng-model="relatorio.dataini" required>
<input class="form-control datafim" type="date" name="data_fim" ng-model="relatorio.datafim" required>
<a class="btn btn-success" ng-disabled="relatorioPorPeriodo.$invalid" ng-click="pesquisaPorPeriodo(relatorio)">Pesquisar</a>
</form>
Controller
app.controller("RelatorioPorPeriodoCtrl", ['$scope', '$http', '$window', '$rootScope', '$routeParams', 'moment', function ($scope, $http, $window, $rootScope, $routeParams, moment) {
$scope.idempresa = $rootScope.idempresa = localStorage.getItem('idempresa');
$scope.empresa = $rootScope.empresa = localStorage.getItem('empresa');
$scope.usuario = $rootScope.usuario = localStorage.getItem('usuario');
$scope.idusuario = $rootScope.idusuario = localStorage.getItem('idusuario');
$scope.pesquisaPorPeriodo = function(relatorio){
console.log(relatorio);
}
}]);
I advise using the library Moment,js (https://momentjs.com/) to handle date formats, time interval counts, etc. Use the function Moment(). format(").
– Paulo Ramos
Yes, I do, but I don’t know how to use it, because in the given example I have to put the date in hand.
– GustavoSevero
How do I install it to use with angular? Can’t install with npm? Or download?
– GustavoSevero
Package npm for Angular: https://www.npmjs.com/package/angular-moment
– Paulo Ramos