How do I get the Month of a datetime stamp to show in a new column

  • I would like to show the month of the date-time stamp in a new column within the table?

    SELECT ContId

    ,CreditL

    ,CreatedOn

    FROM dbo.ContactBase

    ContId CreditL CreatedOn

    1001 NULL2012-05-10 10:12:24.000

    1002 NULL2012-05-10 16:10:48.000

    1003 NULL2012-05-10 16:16:06.000

    1004 NULL2012-05-10 16:25:54.000

    1005 NULL2012-05-10 16:29:55.000

  • it depends on what you mean by "month", either the number or the name:

    there's some handy built in functions to help:

    SELECT ContId

    ,CreditL

    ,CreatedOn,

    MONTH(CreatedOn) As MonthNumber,

    DATENAME(month,CreatedOn) As MonthName

    FROM dbo.ContactBase

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Yes Brilliant thank you!!

    ContId CreditL CreatedOn MonthNumber MonthName

    1001 NULL 2012-05-10 10:12:24.0005 May

    1002 NULL 2012-05-10 16:10:48.0005 May

    1003 NULL 2012-05-10 16:16:06.0005 May

    1004 NULL 2012-05-10 16:25:54.0005 May

    Cheers!

  • 🙂

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

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