Hi,
How to set default saturday value in datecontrol
when i open the form by default display last saturday value
Ex:today wednesday (20-05-2020)
i need to display default last saturday value (16-05-2020)
Could you please help me
Hi mahesh213,
Refer below code.
HTML
<html> <head> <title></title> <meta charset="utf-8" /> <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" /> <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker.min.css" /> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript" src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.9/angular.min.js"></script> <script type="text/javascript"> var app = angular.module('MyApp', []); app.directive('datepicker', function () { return { restrict: 'A', // Always use along with an ng-model require: '?ngModel', link: function (scope, element, attrs, ngModel) { if (!ngModel) return; var todayHighlight = !attrs.todayHighlight ? false : true; ngModel.$render = function () { element.datepicker('update', ngModel.$viewValue || ''); }; element.datepicker({ format: 'dd/mm/yyyy', todayHighlight: todayHighlight }).on("changeDate", function (event) { scope.$apply(function () { ngModel.$setViewValue(event.date); }); }); } }; }); app.controller('MyController', function ($scope) { var today = new Date(); var lastSaturday = new Date(today.getFullYear(), today.getMonth(), today.getDate() - today.getDay() - 1); lastSaturday = lastSaturday.getDate() + "/" + (lastSaturday.getMonth() + 1) + "/" + lastSaturday.getFullYear(); $scope.eventdate = lastSaturday; }); </script> </head> <body ng-app="MyApp" ng-controller="MyController"> <input datepicker ng-model="eventdate" today-highlight="true" /> </body> </html>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.