File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes Date default in SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Date default in SQL Server" Watch "Date default in SQL Server" New topic

Date default in SQL Server


Joined: Aug 13, 2001
Posts: 4
I just started working with MS SQL Server, i imported my database from MS Access, and now i would like to set the date to a default dd/mm/yy without the time and the 4 digits in the year.
I have used getdate()but this gives me full date and time.
How can i achieve this?
Many thanks for any help.
Ranch Hand

Joined: Aug 06, 2001
Posts: 34
public String sqlDateString()
//U can get system time
long time= System.currentTimeMillis();
//It 's convert the system time to java.sql.Date
java.sql.Date systemsqldate=new java.sql.Date(time);

// manifulate the date using the this class
SimpleDateFormat formatter = new SimpleDateFormat ("dd-MM-yyyy");

//sqldate convert the java.util.Date because Using java.util.Date and SimpleDateFormat
// we can manifulate
java.util.Date dateString=(java.util.Date)systemsqldate;

String newDate =null;
newDate = formatter.format(dateString);
}catch(Exception e){
return newDate;
If I'm wrong ..correct me

Dil se....,<BR>Dayanand<BR>0065-8839071(off)<BR>0065-7547034(Res0

Joined: Aug 13, 2001
Posts: 4
I think i understand what you want to do, but as i explained in my email this is my second day using ms sql server, and i wouldnt know where to stick all the code, i was thinking i could sort my problem out along these lines
@MyDate DateTime
DECLARE @DateOnly DateTime
SELECT @DateOnly = CONVERT(DateTime,CONVERT(VARCHAR(8),@MyDate,103))
FROM Members, Activity
WHERE cp_date = @DateOnly
(although i dont know how to connect the procedure with the two date fields in my two tables). Thanks for your help.
I agree. Here's the link:
subject: Date default in SQL Server