var registerDateRange = (function(option){ var dateRange = {}; var sysDate = new Date(); switch(option) { case '0' : // all break; case '1' : // this week sysDate.setDate(sysDate.getDate() - (sysDate.getDay() - 1)); dateRange.from = sysDate; dateRange.to = new Date(); break; case '2' : // last week sysDate.setDate(sysDate.getDate() - (sysDate.getDay() + 6)); dateRange.from = sysDate; var toDate = new Date(); toDate.setDate(sysDate.getDate() + 6); dateRange.to = toDate; break; case '3' : // this month sysDate.setDate(sysDate.getDate() - (sysDate.getDate() - 1)); dateRange.from = sysDate; dateRange.to = new Date(); break; case '4' : // last month sysDate.setDate(sysDate.getDate() - sysDate.getDate()); dateRange.to = sysDate; var fromDate = new Date(sysDate); fromDate.setDate(fromDate.getDate() - (fromDate.getDate() - 1) ); dateRange.from = fromDate; break; } return dateRange; })($("#registerDate").val());