February 20, 2012

Forgive Forgive
Lab Rat
40 posts

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:

  1.         QDate m_curdate = QDate::currentDate();
  2.        
  3.         QDate::fromString("2012-02-20").daysTo(m_curDate);

7 replies

February 20, 2012

Deleted Member # 1d173 Deleted Member # 1d173
Lab Rat
41 posts

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

February 20, 2012

Forgive Forgive
Lab Rat
40 posts

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

February 20, 2012

KA51O KA51O
Robot Herder
478 posts

like this

  1. QDate::fromString("2012-02-20").daysTo(m_curDate).toString("yyyy/MM/dd");

February 20, 2012

Andre Andre
Robot Herder
6295 posts

Perhaps you can use QTimeSpan?

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

February 20, 2012

Forgive Forgive
Lab Rat
40 posts
KA51O wrote:
like this @QDate::fromString(“2012-02-20”).daysTo(m_curDate).toString(“yyyy/MM/dd”);@

daysTo() returns an integer.

February 21, 2012

KA51O KA51O
Robot Herder
478 posts

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.

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

February 25, 2012

Forgive Forgive
Lab Rat
40 posts

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)

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

 
  ‹‹ Design Advice      How Can I use Hardware Rendering instead of Software Rendering with QtSDK 4.8.0 on Mac OS X Lion? ››

You must log in to post a reply. Not a member yet? Register here!