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. Code: 1292 SQL State: 22007 --- Incorrect datetime value

Code: 1292 SQL State: 22007 --- Incorrect datetime value

Scheduled Pinned Locked Moved Database
helpdatabasequestionmysqlannouncement
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.
  • S Offline
    S Offline
    Siavash BRY
    wrote on last edited by
    #1

    Recently, I migrated from version 5.7.40-0 to version 8.0.31 of MySQL, but I faced the following error message on the columns that are time. Error :

    Code: 1292 SQL State: 22007 --- Incorrect datetime value: '2023-06-31 23:59:00' for column 'date' at row 1

    MySQL Query :

    SELECT
    DATE(`Date`) AS `Date`,
    COUNT(`Date`) AS `Record count`
    FROM tbl_Pw
    WHERE `Date` BETWEEN '2023-01-01 00:00:00' AND '2023-03-31 23:59:00'
    GROUP BY DATE(`Date`)
    ORDER BY `Date`;

    How can I fix the problem?

    L J R 3 Replies Last reply
    0
    • S Siavash BRY

      Recently, I migrated from version 5.7.40-0 to version 8.0.31 of MySQL, but I faced the following error message on the columns that are time. Error :

      Code: 1292 SQL State: 22007 --- Incorrect datetime value: '2023-06-31 23:59:00' for column 'date' at row 1

      MySQL Query :

      SELECT
      DATE(`Date`) AS `Date`,
      COUNT(`Date`) AS `Record count`
      FROM tbl_Pw
      WHERE `Date` BETWEEN '2023-01-01 00:00:00' AND '2023-03-31 23:59:00'
      GROUP BY DATE(`Date`)
      ORDER BY `Date`;

      How can I fix the problem?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The DATE type does not include a time value, see https://dev.mysql.com/doc/refman/8.0/en/datetime.html#:~:text=MySQL%20retrieves%20and%20displays%20DATE,%3Amm%3Ass%20'%20format.[^].

      S 1 Reply Last reply
      0
      • L Lost User

        The DATE type does not include a time value, see https://dev.mysql.com/doc/refman/8.0/en/datetime.html#:~:text=MySQL%20retrieves%20and%20displays%20DATE,%3Amm%3Ass%20'%20format.[^].

        S Offline
        S Offline
        Siavash BRY
        wrote on last edited by
        #3

        thanks for your quick answer date is field name not data type and its data type is DATETIME

        SELECT
        DATE(`MyDateColumn`) AS `Date`,
        COUNT(`MyDateColumn`) AS `Record count`
        FROM tbl_Pw
        WHERE `MyDateColumn` BETWEEN '2023-01-01 00:00:00' AND '2023-03-31 23:59:00'
        GROUP BY DATE(`MyDateColumn`)
        ORDER BY `MyDateColumn`;

        L 1 Reply Last reply
        0
        • S Siavash BRY

          thanks for your quick answer date is field name not data type and its data type is DATETIME

          SELECT
          DATE(`MyDateColumn`) AS `Date`,
          COUNT(`MyDateColumn`) AS `Record count`
          FROM tbl_Pw
          WHERE `MyDateColumn` BETWEEN '2023-01-01 00:00:00' AND '2023-03-31 23:59:00'
          GROUP BY DATE(`MyDateColumn`)
          ORDER BY `MyDateColumn`;

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          My apologies, I misread the question. The actual problem is as shown in the error message:

          Incorrect datetime value: '2023-06-31 23:59:00'

          The month of June (06) contains only 30 days, not 31. You will need to manually correct that field.

          1 Reply Last reply
          0
          • S Siavash BRY

            Recently, I migrated from version 5.7.40-0 to version 8.0.31 of MySQL, but I faced the following error message on the columns that are time. Error :

            Code: 1292 SQL State: 22007 --- Incorrect datetime value: '2023-06-31 23:59:00' for column 'date' at row 1

            MySQL Query :

            SELECT
            DATE(`Date`) AS `Date`,
            COUNT(`Date`) AS `Record count`
            FROM tbl_Pw
            WHERE `Date` BETWEEN '2023-01-01 00:00:00' AND '2023-03-31 23:59:00'
            GROUP BY DATE(`Date`)
            ORDER BY `Date`;

            How can I fix the problem?

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

            So summing up the other posts and from the OP. Basically it appears that your database itself has invalid data. How could that happen? Something pushed it in there before it was validated. Or perhaps there is some problem with timezones and/or an actual bug in the database itself. You might be able to fix a timezone problem but otherwise you would need to update the row to put a correct value in there. If it was me I would expect that there is other invalid data in that table and perhaps other tables with timestamps also. You would need to uniquely identify each row then craft an update statement to force that column to a correct (manually determined) value.

            1 Reply Last reply
            0
            • S Siavash BRY

              Recently, I migrated from version 5.7.40-0 to version 8.0.31 of MySQL, but I faced the following error message on the columns that are time. Error :

              Code: 1292 SQL State: 22007 --- Incorrect datetime value: '2023-06-31 23:59:00' for column 'date' at row 1

              MySQL Query :

              SELECT
              DATE(`Date`) AS `Date`,
              COUNT(`Date`) AS `Record count`
              FROM tbl_Pw
              WHERE `Date` BETWEEN '2023-01-01 00:00:00' AND '2023-03-31 23:59:00'
              GROUP BY DATE(`Date`)
              ORDER BY `Date`;

              How can I fix the problem?

              R Offline
              R Offline
              RedDk
              wrote on last edited by
              #6

              I got this off SO, wrt "Code: 1292 SQL State: 22007": "Change the system timezone to the one that does not use DST ..." Who knows why, right? When everything you always wanted to know about anything was everywhere. Exactly as it is, I mean.

              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