diff --git a/dist/sb-date-select.min.js b/dist/sb-date-select.min.js
index 10e7815..91800f4 100644
--- a/dist/sb-date-select.min.js
+++ b/dist/sb-date-select.min.js
@@ -1 +1 @@
-angular.module("sbDateSelect",[]).directive("sbDateSelect",[function(){return{restrict:"A",replace:!0,template:['
','",'",'","
"].join(""),require:"ngModel",scope:{selectClass:"@sbSelectClass",min:"@min",max:"@max"},link:function(e,t,a,n){function s(){e.years=[];for(var t=c.year();t>=m.year();t--)e.years.push(t)}function o(){e.months=[];for(var t=e.year&&m.isSame([e.year],"year")?m.month():0,a=e.year&&c.isSame([e.year],"year")?c.month():11,n=moment.months(),s=t;s<=a;s++)e.months.push({name:n[s],value:s+1});(e.month-1>a||e.month-1s)&&delete e.date}var m,c;e.$watchCollection("[min, max]",function(e){m=moment(e[0]||"1900-01-01"),c=moment(e[1]),l(),o(),s()}),e.$watch("year",function(){o()}),e.$watchCollection("[month, year]",function(){l()}),e.$watchCollection("[date, month, year]",function(){if(e.year&&e.month&&e.date){var t=moment([e.year,e.month-1,e.date]);n.$setViewValue(t.format("YYYY-MM-DD"))}else n.$setViewValue()}),n.$render=function(){if(n.$viewValue){var t=moment(n.$viewValue);e.year=t.year(),e.month=t.month()+1,e.date=t.date()}}}}}]);
\ No newline at end of file
+angular.module("sbDateSelect",[]).directive("sbDateSelect",[function(){return{restrict:"A",replace:!0,template:['','",'",'","
"].join(""),require:"ngModel",scope:{selectClass:"@sbSelectClass",min:"@min",max:"@max"},link:function(e,t,a,n){function s(){e.years=[];for(var t=c.year();t>=m.year();t--)e.years.push(t)}function o(){e.months=[];for(var t=e.year&&m.isSame([e.year],"year")?m.month():0,a=e.year&&c.isSame([e.year],"year")?c.month():11,n=moment.months(),s=t;s<=a;s++)e.months.push({name:n[s],value:s+1});(e.month-1>a||e.month-1s)&&delete e.date}var m,c,r=a.sbDateFormat||"YYYY-MM-DD";e.$watchCollection("[min, max]",function(e){m=moment(e[0]||"1900-01-01"),c=moment(e[1]),l(),o(),s()}),e.$watch("year",function(){o()}),e.$watchCollection("[month, year]",function(){l()}),e.$watchCollection("[date, month, year]",function(){if(e.year&&e.month&&e.date){var t=moment([e.year,e.month-1,e.date]);n.$setViewValue("toDate"===r?t.toDate():t.format(r))}else n.$setViewValue()}),n.$render=function(){if(n.$viewValue){var t=moment(n.$viewValue);e.year=t.year(),e.month=t.month()+1,e.date=t.date()}}}}}]);
\ No newline at end of file
diff --git a/src/sb-date-select.js b/src/sb-date-select.js
index 3b8b032..060a0d5 100644
--- a/src/sb-date-select.js
+++ b/src/sb-date-select.js
@@ -30,7 +30,8 @@ angular.module('sbDateSelect', [])
},
link: function(scope, elem, attrs, model) {
- var min, max;
+ var min, max;
+ var format = attrs.sbDateFormat || 'YYYY-MM-DD';
scope.$watchCollection('[min, max]', function(vals) {
min = moment(vals[0] || '1900-01-01');
@@ -52,7 +53,7 @@ angular.module('sbDateSelect', [])
scope.$watchCollection('[date, month, year]', function () {
if (scope.year && scope.month && scope.date) {
var m = moment([scope.year, scope.month-1, scope.date]);
- model.$setViewValue(m.format('YYYY-MM-DD'));
+ model.$setViewValue(format === 'toDate' ? m.toDate() : m.format(format));
}
else {
model.$setViewValue();