Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date default in SQL Server

 
natx
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
DAYANAND BURAMSHETTY
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
try{
newDate = formatter.format(dateString);
}catch(Exception e){
e.printStackTrace();
}
return newDate;
}
If I'm wrong ..correct me
 
natx
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
CREATE PROCEDURE users_date
@MyDate DateTime
AS
DECLARE @DateOnly DateTime
SELECT @DateOnly = CONVERT(DateTime,CONVERT(VARCHAR(8),@MyDate,103))
SELECT *
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic