Results 1 to 11 of 11

Thread: Qstring to Qdate and vice versa

  1. #1
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Qstring to Qdate and vice versa

    How to convert Qstring to date??? and again date to Qstring....? Means i want Qstring of type dd-MMM-yyyy to yyyy-MM-dd...?
    Qstring str="11-Feb-2013" Now i wants the string in "2013-02-11"..?
    What i tried is
    QDate da=QDate::fromString(str,"dd-MMM-yyyy");
    qDebug()<<"FINALISED DATE____________##########"<<da.toString("yyyy-MM-dd");

    ---------------Output---------
    FINALISED DATE____________########## ""
    its printing empty string please correct me...?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qstring to Qdate and vice versa

    What does qDebug() << da print?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qstring to Qdate and vice versa

    Hi,
    First check if the date was assigned at all with some predefiend Qt format e.g. QDate::toString(Qt:efaultLocaleShortDate). If this will be empty it means that the date is invalid and "fromString" failed.

  4. #4
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Re: Qstring to Qdate and vice versa

    thanks for addressing wysota ............it prints QDate("") ...? WHy is that so....wats wrong in my first statement...?

    airproject thanks for reply.....I didnt get u .????

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qstring to Qdate and vice versa

    What is Yours locale ? if it is not some English the name of the month will not be recognized.
    What You have from this :
    Qt Code:
    1. qDebug << QDate(2013,2,11).toString("dd-MMM-yyyy);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Re: Qstring to Qdate and vice versa

    thanks for addressing lesiok ...the o/p i am getting is "11-Feb-2013"

  7. #7
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qstring to Qdate and vice versa

    Hi, i meant to check if the date is valid first:
    Qstring str="11-Feb-2013";
    QDate da=QDate::fromString(str,"dd-MMM-yyyy");
    if(da.isValid())
    qDebug()<<"FINALISED DATE____________##########"<<da.toString(QtefaultLocaleShortDate);

    regards.

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qstring to Qdate and vice versa

    Quote Originally Posted by sai_3289 View Post
    thanks for addressing lesiok ...the o/p i am getting is "11-Feb-2013"
    So it should working

  9. #9
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Re: Qstring to Qdate and vice versa

    Hi,
    @lesiok :but its not working ....i am not getting wat exactly the problem is ..?
    @airproject :when i print directly "da" it prints QDate("") ...?so it wont go to if loop at all...?

    Guys Please me as it is very urgent or guide me any other through which i can slove my problem ....?


    Regards
    Beginner


    Added after 26 minutes:


    Hi,

    Sorry Guys...problem was solved............. i have given like this QDate da=QDate::fromString(str,"dd-MMM-yyy") where i am missing one 'Y' in this.....
    Last edited by sai_3289; 12th February 2013 at 05:29.

  10. #10
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qstring to Qdate and vice versa

    Next time : don't retype the code but use "copy & paste"

  11. #11
    Join Date
    Jul 2012
    Posts
    40
    Qt products
    Qt4 Qt/Embedded

    Default Re: Qstring to Qdate and vice versa

    Hi,

    Yeah sure Lesiok.....Thankzzzzz

Similar Threads

  1. kde pid from window id and vice versa
    By sky in forum KDE Forum
    Replies: 2
    Last Post: 18th May 2013, 09:17
  2. Replies: 3
    Last Post: 13th May 2011, 13:46
  3. Replies: 10
    Last Post: 15th March 2011, 14:14
  4. conversion between string to hex and vice versa
    By mohanakrishnan in forum Newbie
    Replies: 2
    Last Post: 5th December 2009, 11:25
  5. Convert QByteArray to object and vice versa
    By DiamonDogX in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2009, 20:07

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.