+ Reply to Thread
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
    203
    Thanks
    61
    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
    23
    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
    3,609
    Thanks
    211
    Thanked 554 Times in 544 Posts
    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

    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.

+ Reply to Thread

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, 21:43
  2. Display more than four digits/characters
    By StarRocks in forum Newbie
    Replies: 8
    Last Post: 2nd February 2013, 09:12
  3. All digits of float to QString
    By timmu in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2012, 07:20
  4. setNum() digits question
    By tommy in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2008, 15:19
  5. coordinal significant digits
    By nitriles in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2007, 15: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