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. pysiede2 date and time manuplilation from sqlite3 database
Forum Updated to NodeBB v4.3 + New Features

pysiede2 date and time manuplilation from sqlite3 database

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

    hello there i have been stuck with an issue over a month now , i am trying to retrieve data which was added on the current day from sqite3 database, if i try to use strftime('%d', saledate) to retrieve/query data of the current day from the saledate column it does not work as expected```
    self.conn = sqlite3.connect("database.db")
    self.c = self.conn.cursor()
    self.c.execute("CREATE TABLE IF NOT EXISTS sales(name TEXT, KSH INTEGER, saledate TIMESTAMP)")

    d_s = self.c.execute("SELECT SUM(KSH) FROM sales GROUP BY strftime('%d', saledate), strftime('%d', saledate)").fetchone()
    d_s = float(''.join(map(str, d_s)))
    self.ui.label_28.setText(str(d_s))
    self.ui.label_28.setFont(QFont("Times", 20))
    self.ui.label_28.setStyleSheet("QLabel { background-color: rgb(44, 44, 44);color : white; }")
    self.connection.close()

    thankyou
    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @erico said in pysiede2 date and time manuplilation from sqlite3 database:

      if i try the method below it doesn't work

      This is no error description at all...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        What do you mean by does not work as expected ?
        What do you have in your database ?
        Are you sure you are starting with a non empty database ?
        Why are you grouping twice with the same date ?
        Why do you need strftime in the first place ?

        By the way, you are using the SQLite Python library, you will likely have better chance to get an answer on a Python forum.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • E erico

          hello there i have been stuck with an issue over a month now , i am trying to retrieve data which was added on the current day from sqite3 database, if i try to use strftime('%d', saledate) to retrieve/query data of the current day from the saledate column it does not work as expected```
          self.conn = sqlite3.connect("database.db")
          self.c = self.conn.cursor()
          self.c.execute("CREATE TABLE IF NOT EXISTS sales(name TEXT, KSH INTEGER, saledate TIMESTAMP)")

          d_s = self.c.execute("SELECT SUM(KSH) FROM sales GROUP BY strftime('%d', saledate), strftime('%d', saledate)").fetchone()
          d_s = float(''.join(map(str, d_s)))
          self.ui.label_28.setText(str(d_s))
          self.ui.label_28.setFont(QFont("Times", 20))
          self.ui.label_28.setStyleSheet("QLabel { background-color: rgb(44, 44, 44);color : white; }")
          self.connection.close()

          thankyou
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @erico
          In addition to the preceding comments.

          I am not a SQLite user, so I may be mistaken about the following, it;s just for you to check. But even if your query "works"

          i am trying to retrieve data which was added on the current day

          • Does your table only contain dates in the current month? Else I don't see how your code won't amalgamate rows with the same day but on different months?

          • fetchone(): Why do you thing this would return something on "the current day" (I take that to mean "today", maybe that's not what you mean)?

          You might want to play with your proposed query in one of the available "SQLite Workbench"-type applications, so that you can be sure it behaves as you intend before involving any Qt issues.

          1 Reply Last reply
          1

          • Login

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