Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Extract only hour from a qdatetime.
Forum Update on Monday, May 27th 2025

Extract only hour from a qdatetime.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.1k Views
  • 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.
  • E Offline
    E Offline
    emp1953
    wrote on last edited by
    #1

    Finding lots of examples on line about how to format the output of a qdatetime. Dozens of methods. No where can I find an example that ONLY extracts the hour.
    I have an application that has to perform specific operations on given hours. Can anyone provide a link to such an example or just one code snippet to get this accomplished.
    Thanks for any help

    1 Reply Last reply
    1
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      QDateTime::time() gives you a QTime value and QTime::hour() gives you the hour value.

      QDateTime timestamp = ...
      int hour = timestamp.time().hour();
      

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      6
      • E Offline
        E Offline
        emp1953
        wrote on last edited by
        #3

        Excellent that does it. Thank You. How do I mark this a as solved?

        ODБOïO 1 Reply Last reply
        0
        • E emp1953

          Excellent that does it. Thank You. How do I mark this a as solved?

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @emp1953 said in Extract only hour from a qdatetime.:

          How do I mark this a as solved?

          Topic tools, bottom right corner

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved