Java Utililty Methods SQL Date Parse

List of utility methods to do SQL Date Parse

Description

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

Method

DatestringToSqlDate(String date)
string To Sql Date
Date sql = java.sql.Date.valueOf(date);
return sql;
java.sql.DatestringToSqlDate(String dateVal)
This method is used to convert the date String in the format of "yyyy-MM-dd" to Sql Date
if (dateVal != null && !"".equals(dateVal)) {
    java.sql.Date sqlDate = java.sql.Date.valueOf(dateVal);
    return sqlDate;
} else {
    return null;
java.sql.DatestringToSQLDate(String pstrValue, String pstrDateFormat)
String convert to SQLDate.
if ((pstrValue == null) || (pstrValue.equals(""))) {
    return null;
Date dttTempDate = stringToDate(pstrValue, pstrDateFormat);
return new java.sql.Date(dttTempDate.getTime());
java.sql.DatestringToSqlDate(String str)
string To Sql Date
return dateToSqlDate(stringToDate(str));
StringStrToDate(String Formate, String date)
Str To Date
Calendar c = Calendar.getInstance();
try {
    c.set(Calendar.YEAR, Integer.parseInt(date.substring(0, 4)));
    c.set(Calendar.MONTH, Integer.parseInt(date.substring(5, 7)) - 1);
    c.set(Calendar.DATE, Integer.parseInt(date.substring(8, 10)));
    java.util.Date d = c.getTime();
    SimpleDateFormat f = new SimpleDateFormat(Formate);
    return f.format(d);
...
DatestrToDate(String str)
str To Date
Date date = null;
try {
    SimpleDateFormat sdate = new SimpleDateFormat("yyyy-MM-dd");
    date = (Date) sdate.parse(str);
} catch (Exception e) {
    e.getStackTrace();
return date;
...
CalendarstrToDate(String strDate, String formator)
str To Date
if (strDate == null || formator == null) {
    throw new NullPointerException("The arguments are null !");
Calendar date = Calendar.getInstance();
date.setTime(java.sql.Date.valueOf(strDate));
return date;
TimestampstrToDate(String stringDate)
str To Date
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
if (stringDate != null) {
    java.util.Date dateResult = formatter.parse(stringDate);
    return new Timestamp(dateResult.getTime());
return null;
java.util.DateStrToDate(String val)
Convert a string date in the YYYY-MM-DD format into a java.sql.Date object.
Calendar cal = Calendar.getInstance();
if (val != null) {
    StringTokenizer st = new StringTokenizer(val, "-");
    int temp = Integer.parseInt(st.nextToken());
    if (temp < 100) {
        if (temp > 70) {
            temp += 1900;
        } else {
...
java.sql.DatestrToDate(String value, String pattern)
str To Date
if (value.length() <= 10)
    value = value + " 00:00:00";
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(pattern);
java.text.ParsePosition pos = new java.text.ParsePosition(0);
return new java.sql.Date(format.parse(value, pos).getTime());