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. sql

sql

Scheduled Pinned Locked Moved Database
databasehelp
6 Posts 4 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.
  • T Offline
    T Offline
    Thanusree Duth
    wrote on last edited by
    #1

    I required only time in select query from datetime field in format like: 2:20:55 AM. Pls help me

    J R 2 Replies Last reply
    0
    • T Thanusree Duth

      I required only time in select query from datetime field in format like: 2:20:55 AM. Pls help me

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      That is presentation logic, use your presentation layer to format a datetime instance appropriately. This should start you off:

      var now = DateTime.Now;
      Console.WriteLine(now.ToString("h:mm:ss"));

      More info: Date / Time format strings[^] edit: read the forum guidlines for posting messages; pay specific attention to the subject line requirements.

      R 1 Reply Last reply
      0
      • T Thanusree Duth

        I required only time in select query from datetime field in format like: 2:20:55 AM. Pls help me

        R Offline
        R Offline
        R Giskard Reventlov
        wrote on last edited by
        #3

        There are a number of ways you can do this. Here is one:

        select convert(nvarchar, getdate(), 8) TheTime

        Here is another:

        select substring(convert(nvarchar, getdate(), 22), 10, 11) TheTime

        "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

        1 Reply Last reply
        0
        • J J4amieC

          That is presentation logic, use your presentation layer to format a datetime instance appropriately. This should start you off:

          var now = DateTime.Now;
          Console.WriteLine(now.ToString("h:mm:ss"));

          More info: Date / Time format strings[^] edit: read the forum guidlines for posting messages; pay specific attention to the subject line requirements.

          R Offline
          R Offline
          R Giskard Reventlov
          wrote on last edited by
          #4

          He may have a specific (and valid) reason for needing times in his sql.

          "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

          J 1 Reply Last reply
          0
          • R R Giskard Reventlov

            He may have a specific (and valid) reason for needing times in his sql.

            "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            I highly doubt it. See his post below this one. In addition, I cannot think of a valid reason to format a date, or time, into a string in sql. can you?

            M 1 Reply Last reply
            0
            • J J4amieC

              I highly doubt it. See his post below this one. In addition, I cannot think of a valid reason to format a date, or time, into a string in sql. can you?

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              I don't have a problem with the splitting of the date/time I can think of a number of valid reasons to do that in SQL. What had I missed was that he had stored the data as text, I assumed it was datetime.

              Never underestimate the power of human stupidity RAH

              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