Results 1 to 3 of 3

Thread: qdate from string with one or two day digits and one or two month digits

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default qdate from string with one or two day digits and one or two month digits

    Can't figure out how to specify format for QDate::fromString call where the string is a date with one or two digits for day and month. For example: 1/12/2018 or 01/12/2018, or 1/1/2018 vs 01/01/2018. Advice is greatly appreciated.

    Thanks

  2. #2
    Join Date
    Feb 2015
    Location
    Poland
    Posts
    34
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: qdate from string with one or two day digits and one or two month digits

    I am afraid that you have to call 4 times QDate::fromString (with different params for each case) and verify it by QDate::isValid...

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qdate from string with one or two day digits and one or two month digits

    So don't use QDate::fromString().

    Qt Code:
    1. QStringList dateList = dateString.split( '/' );
    2.  
    3. QDate date;
    4. if ( dateList.length() == 3 )
    5. {
    6. int month = dateList.at( 0 ).toInt();
    7. int day = dateList.at( 1 ).toInt();
    8. int year = dateList.at( 2 ).toInt();
    9. date.setDate( year, month, day );
    10. }
    11. else
    12. // error
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. String ( QbyteArray ) to Double Value with 6 decimal digits
    By persianpatient in forum Qt Programming
    Replies: 2
    Last Post: 30th August 2015, 22:43
  2. Display more than four digits/characters
    By StarRocks in forum Newbie
    Replies: 8
    Last Post: 2nd February 2013, 10:12
  3. All digits of float to QString
    By timmu in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2012, 08:20
  4. setNum() digits question
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2008, 16:19
  5. coordinal significant digits
    By nitriles in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2007, 16:54

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.