Java Utililty Methods SQL Date Create

List of utility methods to do SQL Date Create

Description

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

Method

StringgetCurrentDateString()
get Current Date String
return getCurrentDateString("yyyyMMdd");
TimestampgetCurrentDateWithMinutePrecision()
Gets the current date with minute precision.
Calendar c = new GregorianCalendar();
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Timestamp ts = new Timestamp(c.getTimeInMillis());
return ts;
TimestampgetCurrentDayStartDate(Date date)
get Current Day Start Date
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(date);
rightNow.set(Calendar.HOUR_OF_DAY, 0);
rightNow.set(Calendar.MILLISECOND, 0);
rightNow.set(Calendar.SECOND, 0);
rightNow.set(Calendar.MINUTE, 0);
rightNow.set(Calendar.MONTH, rightNow.get(Calendar.MONTH));
return new Timestamp(rightNow.getTimeInMillis());
...
java.sql.DategetCurrentDBDate()
get Current DB Date
java.sql.Date current = new java.sql.Date(System.currentTimeMillis());
return current;
java.sql.DategetCurrentSQLDate()
get Current SQL Date
return dateToSqlDate(getCurrentDate());
java.sql.DategetCurSQLDate()
Get current date in form of java.sql.Date.
return new java.sql.Date(new Date().getTime());
StringgetCurSQLDateInString(String pstrDateFormat)
Get current date in form of java.sql.Date and then convert it into String.
String pstrDateTime = null;
if ((pstrDateFormat != null) && (!pstrDateFormat.equals(""))) {
    java.util.Date curDateTime = new java.util.Date();
    java.sql.Date curSqlDateTime = new java.sql.Date(curDateTime.getTime());
    SimpleDateFormat sdf = new SimpleDateFormat(pstrDateFormat);
    pstrDateTime = sdf.format(curSqlDateTime);
return pstrDateTime;
...
java.sql.DategetDataMaior(java.sql.Date data1, java.sql.Date data2)
Compara 2 datas e retorna a maior, verificando os nulos.
if (data1 == null)
    return data2;
if (data2 == null)
    return data1;
if (data1.after(data2)) {
    return data1;
} else {
    return data2;
...
DategetDateAfter(Date date, Integer after)
get Date After
if (after == 0) {
    return new Date(date.getTime());
Date d = new Date(date.getTime());
for (int i = 0; i < after; i++) {
    d.setTime(d.getTime() + 86400000);
return d;
...
DategetDateAfter(Date date, long offset)
get Date After
long offsettime = 1000 * 60 * 60 * 24 * offset;
long t = date.getTime() + offsettime;
return new Date(t);