Java Date Add addDateParam(String dtstr, boolean start, List where)

Here you can find the source of addDateParam(String dtstr, boolean start, List where)

Description

Adds a date parameter (start, end) as filter to the SQL where clause

License

Open Source License

Declaration

public static final void addDateParam(String dtstr, boolean start, List<String> where) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

public class Main {
    /**//  w w w.ja v  a 2  s  . com
     * Adds a date parameter (start, end) as filter to the SQL where clause
     */
    public static final void addDateParam(String dtstr, boolean start, List<String> where) {
        if (dtstr != null && isValidDate(dtstr)) {
            where.add("c.loginTime " + (start ? ">= '" : "<= '") + dtstr.substring(0, 4) + "-"
                    + dtstr.substring(4, 6) + "-" + dtstr.substring(6) + " 00:00:00.000'");
        }
    }

    /**
     * Validates the date string to conform with the format "YYYYMMDD"
     */
    public static final boolean isValidDate(String inDate) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        dateFormat.setLenient(false);
        try {
            dateFormat.parse(inDate.trim());
        } catch (ParseException pe) {
            return false;
        }
        return true;
    }
}

Related

  1. addDate(String date, String type, int into)
  2. addDate(String date1, String addpart, int num)
  3. addDate(String dt, long day)
  4. addDateByDays(int days)
  5. addDateDay(int day)
  6. addDates(Date startDate, int days)
  7. addDay(Date date, int days)
  8. addDays(Date date1, long days)
  9. addDays(Date dateToAdd, int numberOfDay)