getdate() function SQL SVR 7

  • How do get this function to show only the date and leave off the time? Or is there another function I should be using?

    Thanks webdaddy13

  • hi,

    a quick and dirty way is to convert to a char field :-

    select convert(char(11),getdate())

    HTH

    Paul

  • I appreciate the conversion statement but I really need to know how to autoatically populate that field date_entered without supplying the date from client side or server side programming

  • i think you need to have a time with all datetime fields. the only thing i can think of is to set the time to the same for each row :-

    create table pgr_date_test

    (col1 datetime)

    insert into pgr_date_test

    select convert(char(11),getdate())

    select * from pgr_date_test

    returns :-

    09/10/2003 00:00:00

    you then just need to ignore the time

    Paul

  • quote:


    I appreciate the conversion statement but I really need to know how to autoatically populate that field date_entered without supplying the date from client side or server side programming


    Use Paul's suggection to create a default for the column:

    
    
    ALTER TABLE MyTable ADD CONSTRAINT df_Date_Entered DEFAULT CONVERT(char(8),GETDATE(),112) FOR Date_Entered

    --Jonathan



    --Jonathan

  • thank you guys this forum has really helped me...I will try it out you guys a great

    I hope some day soon I can help you guys

    webdaddy13

  • If look up CONVERT in SQL Books Online then you will see there are a whole load of different formats you can convert the datetime value into. It is very useful!

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply