Retrieving the current date

  • HI. I have a table that has a date field and the developer wants the current date to be the default. when  I set the default to  GETDATE() in table designer, it populated the field with : 7/10/2006 5:09:00 PM. is there a way I can just pull in the data and not the time? 

    Thanks,

    Juanita

  • Juanita - you should use cast or convert to retrieve your date...with "convert" you can use formatting styles...

    select convert(varchar, getdate(), 101)







    **ASCII stupid question, get a stupid ANSI !!!**

  • Don't force the server to perform type conversion from date to string & back again. Use this as teh default:

    dateadd(d, 0, datediff(d, 0, getdate()))

     

  • That doesn't actually strip off the time portion though, or am I missing something?

  • Select getdate() As DateWithTime,

       dateadd(d, 0, datediff(d, 0, getdate())) As DateOnly

    Result:

    DateWithTime            DateOnly

    2006-07-11 07:51:52.353 2006-07-11 00:00:00.000

  • Thank you for the suggestions!!

    Juanita

  • Hmm. I see - I thought Juanita was actually trying to remove the time portion altogether, not just set it to 0.

  • You can't "strip off" time unless you store it as varchar.

    The first post said it is a datetime column, ergo, it must store time but as 00:00:00.000

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

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