user1334858
user1334858

Reputation: 1935

QDate::FromString() issue with QDate.year() always returning -4713

I am trying to add a date to a QDate object. The month and day are placed into the Qdate object correctly but the year always reads back -4713.

Here is my code:

int main(int argv, char *argc[])
{
   // Show all my arguments to make sure they are correct
   qDebug() << "\n";
   for( int i = 0; i < argv ; i++)
   {
      qDebug() << i << ":  " << argc[i] << "\n";
   }

   // Add the yyyy-mm-dd date into date
   QDate date = QDate::fromString(argc[1],"yyyy-mm-dd");

   // Check to see if the date is correct
   qDebug() << "Year: " << date.year() << "\nMonth:" << date.month() << "\nDay" << date.day();
   return 0;

}

Here is what I use in the terminal:

./birthday "1992-01-01"

The output looks like this:

0 : ./birthdays
1 : 1990-01-01
Year: -4713
Month: 1
Day:   1

Now no matter what I choose for my year it always returns -4713. Does anyone know why? I have been stuck on this issue for a while now and do not understand what is going on here.

Upvotes: 0

Views: 503

Answers (1)

Predelnik
Predelnik

Reputation: 5246

Maybe it varies from Qt version to Qt version but for me string wasn't converted at all until I made letters m - capital like "yyyy-MM-dd" then it started working (My version is 5.1.0)

You may also see it here. Ms mentioned are capital.

Upvotes: 3

Related Questions