Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql problem

Author  Topic 

rashmip
Starting Member

4 Posts

Posted - 2005-08-18 : 07:08:13
I have problem is Set DateFormat "ymd" so database date column will have yyyy/mm/dd format.
I am using java technology for inserting & retirval of records .
java date functions retuns date in yyyy/mm/dd format.
java.sql.Date.valueOf().
so format should match & Search is based on date Column.
needs urgent Help
Thanks in advance.

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2005-08-18 : 10:35:24
I would let SQL keep it's default datetime type and handle the date format in the java code. It is not advised to mess with the datetime format in the database.

Aj

Hey, it compiles.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-18 : 10:43:17
Use proper datetime variable in java and assign it the date and insert the record
Did you try that?
What difficulty did you face?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rashmip
Starting Member

4 Posts

Posted - 2005-08-20 : 04:22:06

I am taking user input(from HTML Form)it is coming as String,then Inside servlet converting that String to Date object with

dt1=req.getParameter("txt_dt");
java.sql.Date mydt=java.sql.Date.valueOf(dt1);
return type of this date object is yyyy/mm/dd and sql server smalldatetime is dd/mm/yyyy format so plz advice for same to bring both in same date Format. Then Comparsion can be done this Serach screen where user will give TO and From Date ,records will be retrived based on this query.
Select Query select Enquiry_id,Student_name,Date_enquiry,Status from Enquiry_master where Course='"+Cour1+"'and Date_Enquiry between '"+dt4+"' and '"+dt5+"' order by Student_name ");

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-22 : 01:04:54
No need for conversion
Let the date to be stored in yyyy/mm/dd format
See example here

Declare @t smalldatetime
Set @t = '2005/08/22'
Select @t
Set @t = '2005-08-22'
Select @t


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rashmip
Starting Member

4 Posts

Posted - 2005-08-22 : 04:48:00
i need to store the string in date format to database plus ,later date is to be retived in String format.
u can understand from last reply where i have pasted my java code also .
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-22 : 04:55:19
In your example code, dont declare dt4 and dt5 to be string
Declare them to be datetime and assign datetime value and do query

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -