QDate::daysTo but only with yyyy-MM-dd



  • Well i'm trying to use QDate::daysTo to check the difference between 2 dates. But daysTo param accepts a QDate, but QDate returns: QDate("sun feb 19 2012")

    In easy words.

    I want QDate to only return yyyy-MM-dd and not QDate("sun feb 19 2012") (Today...) something like.. .QDate("2012-02-19") so i can easily do:

    @ QDate m_curdate = QDate::currentDate();

        QDate::fromString("2012-02-20").daysTo(m_curDate);
    

    @



  • you can use this tempDateTime.toString("yyyy/MM/dd") Note MM should be in capital



  • I don't know if i'm understanding you but .daysTo() parameter only allows QDate.



  • like this
    @QDate::fromString("2012-02-20").daysTo(m_curDate).toString("yyyy/MM/dd");@



  • Perhaps you can use QTimeSpan?



  • [quote author="KA51O" date="1329723613"]like this
    @QDate::fromString("2012-02-20").daysTo(m_curDate).toString("yyyy/MM/dd");@[/quote]

    daysTo() returns an integer.



  • Sorry my bad. Didn't really spend too much time on thinking about the problem. I still don't fully understand what your problem is and what you're trying to achieve.

    @
    QDate::fromString("2012-02-20").addDays(QDate::fromString("2012-02-20").daysTo(m_curDate)).toString(“yyyy/MM/dd”);
    @



  • Sorry, what i'm trying to do is to check how many days until a date. I mean, i have 2012-02-20 (20 February 2012). I want to count how many days until today (Since today is 25, 5 days).

    EDIT: Okay, i've got it. Was something like creating a TempDate and doing QDate::fromString("2012-02-20", "yyyy-MM-dd") then doing temp.daysTo(QDate::currentDate)

    @ QDate temp;
    temp = QDate::fromString("2012-02-20", "yyyy-MM-dd");
    qDebug() << temp.daysTo(QDate::currentDate());@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.