• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Date default in SQL Server

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic