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 query for Date field

SQL query for Date field

Scheduled Pinned Locked Moved Database
databasequestionsql-serversysadmin
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.
  • I Offline
    I Offline
    Imtiaz Murtaza
    wrote on last edited by
    #1

    Friends, I've a table in SQL server database. One field in this table is of type "smalldatetime". When i run any query i get the date in the form : 5/6/2004 But i want to get the result in "descriptive" form i.e "Saturday, May 6, 2004". How can i get it with a query ? Imtiaz

    H 1 Reply Last reply
    0
    • I Imtiaz Murtaza

      Friends, I've a table in SQL server database. One field in this table is of type "smalldatetime". When i run any query i get the date in the form : 5/6/2004 But i want to get the result in "descriptive" form i.e "Saturday, May 6, 2004". How can i get it with a query ? Imtiaz

      H Offline
      H Offline
      Henrik Stuart
      wrote on last edited by
      #2

      You can query it like this (just replace GETDATE() with your column): SELECT DATENAME("dw", GETDATE()) + ', ' + DATENAME("m", GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR) + ', ' + CAST(YEAR(GETDATE()) AS VARCHAR) I'd suggest you just query out the DATETIME field and process it in your platform of choice. The .NET framework has, amongst others, very good localisation support for this that you could use to get the proper string for the proper locale setting. The use of DATENAME is dependant on how SQL Server processes it and thus it cannot be formatted to the users' locale/preferences (at least not to my knowledge). Hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])

      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