datepart Help

  • Why the result of this is not 24-07-2006??

    DECLARE @datestring datetime

    SET @datestring = datepart(day, getdate()) - datepart(month, getdate()) - datepart(year, getdate())

    SELECT @datestring

    Thanks

    Claudia


    Regards,

    Cláudia Rego

    www.footballbesttips.com

  • For the same reason these aren't...

    select cast(24 - 7 - 2006 as datetime)

    select cast(-1989 as datetime)

    Maybe one of these is what you're after...

    select replace(convert(varchar(30), getdate(), 103), '/', '-')

    select dateadd(day, datediff(day, 0, getdate()), 0)

    ?

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Try this:

    SELECT CONVERT(CHAR(10),GETDATE(),105)

  • Ah, yes! I looked in BOL and missed 105

    Thanks Karl

    Cláudia - use that instead of 103 with replace (if that was what you needed).

     

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Solved!!

    Thanks a lot

    Cláudia


    Regards,

    Cláudia Rego

    www.footballbesttips.com

Viewing 5 posts - 1 through 5 (of 5 total)

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