Tuesday, November 1, 2011

Convert JAVA DATE to MS SQL datetime format


SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

Date javaDate=new Date();

System.out.println("Java Date : "+javaDate);

String msSqlDate=sdf.format(javaDate).trim();

System.out.println("Ms Sql Date : "+msSqlDate.replace(" ","T"));

insert into DATA (CREATED) values (convert(datetime,'"+msSqlDate+"'));

No comments:

Post a Comment