Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL DATENAME() QUESTION...

SQL DATENAME() QUESTION...

Scheduled Pinned Locked Moved Database
questiondatabasehelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lior654 hotmail com
    wrote on last edited by
    #1

    I have a number representing a month: DECLARE @MONTH INT SET @MONTH = 5 How can I use the DATENAME() function to get the name of the month? I must have a full date variable to use this and I don't know how to build a date using @MONTH as its month... PLEASE HELP...

    C 1 Reply Last reply
    0
    • L lior654 hotmail com

      I have a number representing a month: DECLARE @MONTH INT SET @MONTH = 5 How can I use the DATENAME() function to get the name of the month? I must have a full date variable to use this and I don't know how to build a date using @MONTH as its month... PLEASE HELP...

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      lior654#hotmail.com wrote:

      How can I use the DATENAME() function to get the name of the month?

      DATENAME() can accept a varchar as the date, so you can just create a random date, with the month as you want:

      DECLARE @somedate varchar(20);
      SET @somedate = '2005-01-01';
      SELECT datename(month,@somedate);

      This will return "January". However, I would recommend that user interface type things like getting a month name are best carried out in the UI layer leaving the data layer to get on with things that it is good at (like manipulating the data in the database)


      My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups