Java SQL Date Add AddSqlDate(String strDate, int iDays)

Here you can find the source of AddSqlDate(String strDate, int iDays)

Description

Add Sql Date

License

Open Source License

Declaration

public static java.sql.Date AddSqlDate(String strDate, int iDays)
            throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static java.sql.Date AddSqlDate(String strDate, int iDays)
            throws Exception {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date d1 = df.parse(strDate);
        return new java.sql.Date(AddDate(d1, iDays).getTime());
    }// w w  w  .j  av a  2s .  c om

    /**
     * 
     * @param date
     *            Date
     * @param days
     *            int
     * @return Date
     */
    public static Date AddDate(Date date, int days) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        long lTmp = c.getTimeInMillis();
        c.setTimeInMillis(lTmp + ((long) days) * 24 * 3600 * 1000);
        return c.getTime();
    }
}

Related

  1. addDate(String date)
  2. addDays(Date date, int days)
  3. addDaysToSQLDate(java.sql.Date date, int days)
  4. addMesData(Date dtReferencia, int mes)
  5. addMilliseconds(Date date, int milliseconds)
  6. addYearsToDate(java.sql.Date date, int years)