Java Utililty Methods SQL Date Add

List of utility methods to do SQL Date Add

Description

The list of methods to do SQL Date Add are organized into topic(s).

Method

Dateadd(Date date, int unit, int amount)
add
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(unit, amount);
return c.getTime();
DateaddDate(int add, java.util.Date d)
add Date
return addDate(add, new Date(d.getTime()));
java.util.DateaddDate(java.util.Date date, int day)
add Date
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTimeInMillis(getMillis(date) + ((long) day) * 24 * 3600 * 1000);
return c.getTime();
DateaddDate(String date)
add Date
if (date == null) {
    return null;
Date tempDate = parseDate(C_DATE_PATTON_DEFAULT, date);
String year = format(tempDate, "yyyy");
String month = format(tempDate, "MM");
String day = format(tempDate, "dd");
GregorianCalendar calendar = new GregorianCalendar(Integer.parseInt(year), Integer.parseInt(month) - 1,
...
DateaddDays(Date date, int days)
add Days
return new Date(date.getTime() + 1000 * 60 * 60 * 24 * days);
java.sql.DateaddDaysToSQLDate(java.sql.Date date, int days)
add Days To SQL Date
return new java.sql.Date(date.getTime() + (days * DAY_IN_MILLSEC));
DateaddMesData(Date dtReferencia, int mes)
add Mes Data
Calendar dtLimiteAux = Calendar.getInstance();
dtLimiteAux.setTimeInMillis(dtReferencia.getTime());
dtLimiteAux.add(Calendar.MONTH, mes);
return new Date(dtLimiteAux.getTimeInMillis());
DateaddMilliseconds(Date date, int milliseconds)
add Milliseconds
return add(date, Calendar.MILLISECOND, milliseconds);
java.sql.DateAddSqlDate(String strDate, int iDays)
Add Sql Date
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = df.parse(strDate);
return new java.sql.Date(AddDate(d1, iDays).getTime());
java.sql.DateaddYearsToDate(java.sql.Date date, int years)
add Years To Date
java.sql.Date logicalDate;
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.YEAR, years);
return new java.sql.Date(c.getTimeInMillis());