How to get values from customer dates/Datepicker using ionic


#1

0
down vote
favorite
Here i got small issue i created date selection box where customer can choose 4 options like Day,Week,Month,Custom date

1.If customer chooses Day the from & to date should be current day.

2.If customer chooses Weekthen from date should start Sunday & to date should be current date in week.

If customer chooses Month then from date should start month starting date & to date should be current date in month.
if customer chooses **Custom date then customer should pick his from date and to date.
below is my code i have to wrote code in this below format

code for selecting dates

Report Type {{opt.Type}}
<ion-col col-6>
  <ion-label>Report Type</ion-label>
  <ion-select [(ngModel)]="reportType">
    <ion-option *ngFor="let opt of reportTypes" [value]="opt.TypeId">{{opt.Type}}</ion-option>
  </ion-select>

Code for getting custom dropdown on selecting custom

<ion-row *ngIf="reportType==10">
  <ion-col>
From Date To Date

Typscript code:

this.reportTypes=[{TypeId:1,Type:‘Day’},{TypeId:7,Type:‘Week’},{TypeId:30,Type:‘Month’},{TypeId:10,Type:‘Custom Date’}]

Here i got small issue i created date selection box where customer can choose 4 options like Day,Week,Month,Custom date

1.If customer chooses Day the from & to date should be current day.

2.If customer chooses Weekthen from date should start Sunday & to date should be current date in week.

If customer chooses Month then from date should start month starting date & to date should be current date in month.
if customer chooses **Custom date then customer should pick his from date and to date.
below is my code i have to wrote code in this below format

code for selecting dates

Report Type {{opt.Type}}
<ion-col col-6>
  <ion-label>Report Type</ion-label>
  <ion-select [(ngModel)]="reportType">
    <ion-option *ngFor="let opt of reportTypes" [value]="opt.TypeId">{{opt.Type}}</ion-option>
  </ion-select>

Code for getting custom dropdown on selecting custom

<ion-row *ngIf="reportType==10">
  <ion-col>
From Date To Date Typscript code:

this.reportTypes=[{TypeId:1,Type:‘Day’},{TypeId:7,Type:‘Week’},{TypeId:30,Type:‘Month’},{TypeId:10,Type:‘Custom Date’}]
//////////////calculate date by reportTypes

calculateFromAndToDateByReportype(reportType){
var days; // Days you want to subtract
var currdate = new Date();

if(reportType==1){
this.reportDataFromDate=currdate;
this.reportDataToDate=currdate;
}
else {
var last = new Date(currdate.getTime() - (reportType * 24 * 60 * 60 * 1000));
this.reportDataFromDate=last;
this.reportDataToDate=currdate;
}

}
Till now i got Day ,

But unable to get the Week i.e Starts from Sunday to Current day in Week

Month :-From date should be Month starting date and to date should be month current date

current date: from date should be the selected value and to date should be selected value


#2

I recommend you to use Moment.js, when you dealing with date things. Its very effective.