SQL DateTime 12AM or 00:00:00

Semua segmen waktu setnya adalah 0 dan menggunakan static variable HOUR_OF_DAY (bukan yang Calendar.HOUR soalnya jika HOUR berati yang meridiem alias maksimal 11:59:00 or 12 AM) 0 berarti 00:00:00.

java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND,0);
cal.set(Calendar.SECOND, 0);
java.util.Date utilDate = cal.getTime();
java.sql.Date sqlDate = new Date(utilDate.getTime());
System.out.println(sqlDate);

Ternyata hal seperti ini masih diperlukan ketika pengetahuan SQL date truncate di Oracle terbatas, ya mungkin dapat dianggap ‘akal-akalan’ semata.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.