Comparing date format with java.sql.Dat
Hello,
Wish I could compare a date recovered on a database, so java.sql.Date format, with the date of the day. I have found many ways to get a date format from java.sql.Date to java.util.Date date format. However, to compare two dates, I have found the methods presented in class java.util.Date. My problem is to succeed to convert a date format java.sql.Date java.util.Date order to use the proposed methods of comparison.
Re: Comparing date format with java.sql.Dat
Bin class inherits from the class java.sql.Date java.util.Date There's no problem then the method compareTo() is applied to an object of type java.sql.Date. It should perhaps just be careful to cast properly compare two objects.
Re: Comparing date format with java.sql.Dat
I must get a date for a database and compared to the current day's date for use:
Code:
Date td = new Date ();
and the date of the database in an application that gives the date the form YEAR-MONTH-DAY. How can I compare the two please or retrieve the month of the current date, day and year because getYear () for example does not work. Any more help regarding this topic is appreciated. Thank you.
Re: Comparing date format with java.sql.Dat
I tested a small but doubts persist, for the current date no problem:
Code:
private static Date dt = Calendar.getInstance ();
For the month is what the syntax is correct:
Code:
private static int cal = Calendar.getInstance (). MONTH;
I do not know what exactly to do, any help will be great. Thank you.
Re: Comparing date format with java.sql.Dat
Check out the following code
Code:
public abstract class DateParser
(
/ ** The formatter ** /
private static DateFormat frm = init();
/ ** Initialize the formatter ** /
private static DateFormat init()
( DateFormat frm = new SimpleDateFormat("yyyy-MM -dd HH: mm: ss "); frm.setLenient(false);
return frm;
)
/ ** Convert the string into Date object * @ param String txtDate frm yyyy-mm-dd hh: mm: ss to be converted * @ return Date corresponding (null if input error) ** /
public static Date convert(String txtDate)
(
p = ParsePosition new ParsePosition(0); Date date = frm.parse(txtDate, p);
if( p.getErrorIndex() ! = -1 | | p.getIndex() ! = txtDate.length() ) return null,
return day;
)
)
Re: Comparing date format with java.sql.Dat
As part of a web application, I collect, among other-, two dates with time. To ensure that these dates can be inserted into a database, a set of JavaScript requires the user to fill a date and time in the form yyyy-mm-dd hh: mm: ss.
However, before inserting the data into the database, I need to make sure they check a rule of priority. A date must be earlier than the date B.