SDN Featured Content

Do you Think Hibernate is better technology that EJB

Java/J2EE blogs

Welcome to my java /J2EE blogs.


Friday, December 18, 2009

getting SQL timestamp for the last calender day

Here is a code snippet of getting the sql timestamp for the last calender day

We can also modify the timing in date(currrent or previous), hour, minute or seconds by adding the positive or negative number.

Calendar todayDate = Calendar.getInstance();
todayDate.add(Calendar.DATE, -1);
todayDate.set(Calendar.HOUR_OF_DAY, 0);
todayDate.set(Calendar.MINUTE, 0); // set minute in hour
todayDate.set(Calendar.SECOND, 0); // set second in minute
todayDate.set(Calendar.MILLISECOND, 0);
Date currentDate=todayDate.getTime();
long miliseconds=currentDate.getTime();
java.sql.Timestamp lastDayDate = new java.sql.Timestamp(miliseconds);

No comments: