Results 1 to 5 of 5

Thread: Date and Time Difference

  1. #1
    Join Date
    Aug 2009
    Location
    Saudi Arabia - Buraidah
    Posts
    48
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Date and Time Difference

    Hi,

    Is there a class that return the difference between to given dates?

    Thanks
    Mohammad

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Date and Time Difference

    For days between two dates: Use the QDate class and its daysTo() function. Alternatively, convert both dates using toJulianDay() and subtract one from the other.

    For finer grain than a whole day the QDateTime class has toTime_t(), which can be used in the same way as toJulianDay().
    Last edited by ChrisW67; 21st August 2009 at 04:51.

  3. The following user says thank you to ChrisW67 for this useful post:

    MIH1406 (3rd June 2010)

  4. #3
    Join Date
    Aug 2009
    Location
    Saudi Arabia - Buraidah
    Posts
    48
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Date and Time Difference

    This is good

    Thank you
    Mohammad

  5. #4
    Join Date
    Aug 2012
    Location
    BANGALORE
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Date and Time Difference

    i have a doubt..pls help..

    i have 2 QDateEdits..ie one s start_date and other is end_date..i want to find difference between them and display in a QLineEdit..how to do it?

    i did
    int s=ui->start_date.day();
    int e=ui->end_date.day();
    int diff=e-s; //this works correctly it returns the difference
    Qstring d=diff.toString(); //here am getting junk values y?

    ui->line_edit->setText(d);
    Last edited by hemapriya; 19th August 2012 at 06:59.

  6. #5
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Date and Time Difference

    try daysTo() function.
    Ex:
    Qt Code: Switch view
    QDate date1;
    QDate date2;
    int nDiff = date1.daysTo(date2);
    ui->line_edit->setText(QString::number(nDiff));
    To copy to clipboard, switch view to plain text mode


    Qstring d=diff.toString(); //here am getting junk values y?
    you need to convert the int to string ().


    hope it helps

Similar Threads

  1. time and date issues
    By boog07005 in forum Newbie
    Replies: 5
    Last Post: 20th August 2012, 15:15
  2. How to change the date and time of a system
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2009, 05:55
  3. automatic time and date updating
    By sudheer in forum Qt Tools
    Replies: 1
    Last Post: 17th January 2008, 10:00
  4. to set date and time in the file info of two days back
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2007, 16:54
  5. chage date and time
    By behnia_k in forum General Programming
    Replies: 4
    Last Post: 18th July 2007, 12:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.