Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDate::fromString() fails on certain dates
Qt 6.12 LTS is out! See what's new in the release blog

QDate::fromString() fails on certain dates

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.2k 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.
  • J Offline
    J Offline
    jorge 0
    wrote on last edited by
    #1

    Qt 5.15, Qt 6.0, macOS 11.2 Big Sur. These conversions yield invalid dates:

    qDebug() << QDate::fromString("1978-04-02",  "yyyy-MM-dd");
    qDebug() << QDate::fromString("02-04-1978",  "dd-MM-yyyy");code_text
    

    The following search yields four similar situations (1977-03-27, 1978-04-02, 1979-04-01,
    1980-03-30):

       QString format("yyyy-MM-dd");
       for (int year=1930; year <= 2030; ++year)  {
          QDate date(year,1,1);
          while (date != QDate(year+1,1,1))   {
             QString str = date.toString(format);
             QDate converted = QDate::fromString(str, format);
             if (converted != date)
                qDebug() << date << converted;
             date = date.addDays(1);
          }
       }
    

    Any ideas?

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

      Create a bug report about this. Works fine on linux.

      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
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Can you post the output you get ?

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

        J 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi and welcome to devnet,

          Can you post the output you get ?

          J Offline
          J Offline
          jorge 0
          wrote on last edited by Christian Ehrlicher
          #4

          @SGaist the output is

          QDate("1977-03-27") QDate(Invalid)
          QDate("1978-04-02") QDate(Invalid)
          QDate("1979-04-01") QDate(Invalid)
          QDate("1980-03-30") QDate(Invalid)
          

          Reported as a possible bug, as suggested (QTBUG-91120).

          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
          • Unsolved