I'm trying to initialize a variable called startDate using java.sql.Date.
I've tried...
java.sql.date startDate = "02/04/2015"
But it thinks it's a string.
java.sql.date startDate = 02/04/2015
But it thinks it's an int.
java.sql.date startDate = 02-04-2015
But it displays the error "invalid character constant".
How do I properly initialize this variable?
One possible approach is to use a SimpleDateFormat and the java.sql.Date(long) constructor like
DateFormat df = new SimpleDateFormat("MM-dd-yyyy");
java.sql.Date sqlDate = new java.sql.Date(df.parse("02-04-2015").getTime());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With