获得差异的问题日期

时间:2016-11-21 13:21:04

标签: android date datepicker calendar

我只需要今天和昨天的日期,当选择其他日期时,它应该给出错误....我得到的一切都好,但是有一个小问题 这是我的代码:

  if (flag == 0) {
            if (getday(myCalendar.getTime()) == 1 || getday(myCalendar.getTime()) == 0) {
                setvisitdate();
            }
                Toast.makeText(getApplicationContext(),
                        "Selected date is not valid...", Toast.LENGTH_SHORT)
                        .show();

                flag = 0;
                new DatePickerDialog(FvrActivity.this, date,
                        myCalendar.get(Calendar.YEAR),
                        myCalendar.get(Calendar.MONTH),
                        myCalendar.get(Calendar.DAY_OF_MONTH)).show();
            }

这是getday的方法:

 private int getday(Date selected_date) {

        Calendar selected_cal = Calendar.getInstance();
        selected_cal .setTime(selected_date);
        Calendar c = Calendar.getInstance();
        c.getTime();
        long diffInMillisec = c.getTimeInMillis() - selected_cal.getTimeInMillis();
        long diffInDays = TimeUnit.MILLISECONDS.toDays(diffInMillisec);
        return (int) diffInDays;
  }

假设今天的日期是2016年11月21日...我只想选择21日期而不是22而不是22但是在这里我也可以选择22 ...也许你提前解决。

1 个答案:

答案 0 :(得分:1)

使用此逻辑:

SELECT      @Total = ((CAST(SUM(WorkedTimeInMinutes * KayakoValue) AS FLOAT)/60))
FROM        [VDBSERVER2012\SQLEXPRESS2014].PlaterITDB.dbo.KayakoTimeEntries
INNER JOIN  ClientContract ON ClientId = @ClientId AND Workdate BETWEEN ClientContract.StartDt AND ClientContract.EndDt
WHERE       OrganizationID = @KKId AND WorkDate BETWEEN @StartDate AND @EndDate AND MONTH(WorkDate) = @Month