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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Date format in sql

Date format in sql

Scheduled Pinned Locked Moved Database
databasequestioncsharp
3 Posts 2 Posters 1 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
    imnotso
    wrote on last edited by
    #1

    I've a varchar variable in my stored procedure returning either a date or a piece of text depending on the condtional code. Both return fine but the date comes back as '6 DEC 2007 08:04am' because of the varchar. How do I get it to return in the format 'dd/mm/yyy hh:mm:ss' ? I've tried cast as, convert and the date formatting, it always returns as described. Should I format it in my c# code behind, it that eaiser? Thanks in advance. Harvey

    S 1 Reply Last reply
    0
    • I imnotso

      I've a varchar variable in my stored procedure returning either a date or a piece of text depending on the condtional code. Both return fine but the date comes back as '6 DEC 2007 08:04am' because of the varchar. How do I get it to return in the format 'dd/mm/yyy hh:mm:ss' ? I've tried cast as, convert and the date formatting, it always returns as described. Should I format it in my c# code behind, it that eaiser? Thanks in advance. Harvey

      S Offline
      S Offline
      SimulationofSai
      wrote on last edited by
      #2

      When you convert date to varchar, you can specify styles which will tell how to format the output of the convert function.

      imnotso# wrote:

      How do I get it to return in the format 'dd/mm/yyy hh:mm:ss' ?

      You can try CONVERT(varchar, Getdate(), 131)

      SG Cause is effect concealed. Effect is cause revealed.

      I 1 Reply Last reply
      0
      • S SimulationofSai

        When you convert date to varchar, you can specify styles which will tell how to format the output of the convert function.

        imnotso# wrote:

        How do I get it to return in the format 'dd/mm/yyy hh:mm:ss' ?

        You can try CONVERT(varchar, Getdate(), 131)

        SG Cause is effect concealed. Effect is cause revealed.

        I Offline
        I Offline
        imnotso
        wrote on last edited by
        #3

        Thanks for the quick response, I have tried that but it converts it to a strange date. not the date entered. I have done it in the code behind in c#. Thanks though. Harvey

        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