on 07-21-2006 2:50 PM
How to separate date and time when we select or insert in the SQL in the java method
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.