cancel
Showing results for 
Search instead for 
Did you mean: 

Subject - Datatime function

Former Member
0 Kudos

How to separate date and time when we select or insert in the SQL in the java method

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Receive the Date as java.sql.Date from the Database

then separate it

int date= da.getDate();

int mon=da.getMonth()+1;

int year= da.getYear()+1900;

int hours= da.getHours();

int min= da.getMinutes();

int sec= da.getSeconds();

Concat the date as

String Dateval=date"/"mon"/"year;

String timeval=hours":"sec":"min;

Kind Regards

Mukesh

Former Member
0 Kudos

Hi

Use java.sql.Date from the Database

and use the follwing code is very important

say ToDt=getdate

int Tyear=ToDt.getYear()+1900;

int Tmon=ToDt.getMonth()+1;

int Tdat=ToDt.getDate();

String monstring1= String.valueOf(Tmon);

if(monstring1.length()<=1)

{

monstring1="0"+Tmon;

}

String datetring1= String.valueOf(Tdat);

if(datetring1.length()<=1)

{

datetring1="0"+Tdat;

}

FparseTodate = monstring1"-"datetring1"-"Tyear;

the following code to take the time

************************************

say StrDate=getdate or somedate

StrDate=StrDate.substring(StrDate.indexOf(' '),StrDate.length());

String ToHrs=StrDate.substring(0,StrDate.indexOf(':'));

String ToMin=StrDate.substring(StrDate.indexOf(':')+1,StrDate.lastIndexOf(':'));

String ToSec=StrDate.substring(StrDate.lastIndexOf(':')+1,StrDate.lastIndexOf('.'));

FtoPrintTime=ToHrs + ":" + ToMin + ":" + ToSec;

and finally you should give below line i.e

sqlquery + "and convert(char(10),<getdate>,110) >='"+FparseTodate i.e <convertdate> +"'";

Hope it will be very helpful for you

Regards

Dhinakar J

Answers (0)