outputing Monday 01 Mar 2006??

  • I know this can be done in mySQL can it be done in sql server?

    i have dates in datetime format, but it would be very useful if i could output them in a format that includes the day

    ive had a look on the net but cant seem to find it.

    sorry for the newb question!

    edit

    scrap that. just found a work around....this one just adds weekends along with the name of the day. its an easy hack to get it what i want to do.

    CREATE TABLE WeekEndsAndHolidays (DayOfWeekDate datetime, DayName char(3))

    GO

    SET NOCOUNT ON

    DECLARE @FirstSat datetime, @x int

    SELECT @FirstSat = '1/3/2004', @x = 1

    --Add WeekEnds

    WHILE @x < 52
    BEGIN
    INSERT INTO WeekEndsAndHolidays(DayOfWeekDate, DayName)
    SELECT DATEADD(ww,@x,@FirstSat), 'SAT' UNION ALL
    SELECT DATEADD(ww,@x,@FirstSat+1), 'SUN'
    SELECT @x = @x + 1
    END
    SET NOCOUNT OFF
    GO

  • You can use the hack, or you can use the functionality built into SQL Sever...

    SELECT DATENAME(dw,GETDATE())+' '+CONVERT(CHAR(11),GETDATE(),106)

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

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

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