Link to home
Start Free TrialLog in
Avatar of AntoniRyszard
AntoniRyszard

asked on

Adding date to mysql tables?

Hello,

Using mysql I set a column datestamp to use the date field type.

Could anyone advise if I would use the java.sql.Date object to capture the time-clock to add this in the table?

And having stored the date, would I be-able to query the database datestamp field using a PreparedStatement to return fields with a particular month and year.

Or to query in this way would I need to have a separate, month and year field in the table?

Thank you

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Yes, yes and no ;-)
Bear in mind that sql Date contains no hours, minutes etc.
Avatar of AntoniRyszard
AntoniRyszard

ASKER

Thanks

Could I ask if this seems the correct way of returning the day, month, year.

Calendar calendar = new GregorianCalendar(2006, 0, 1);
java.sql.Date date = new java.sql.Date(calendar.getTime().getTime());
 
And to add the date in a preparedstatement, would I need to use date.toString()?

Could I ask finally,

To return all the records with from march 06 and in ordered on the day. Could we achieve this from the datestamp field, which contains a java.sql.Data value?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)