Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Converting Date Format
Servers for Qt installer are currently down

Converting Date Format

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 13.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vineela
    wrote on 5 Feb 2019, 12:38 last edited by
    #1

    Converting QString date format from "yyyy-MM-dd" to "dd-MM-yyyy"

    this is my QString
    QString dd = "2018-08-01";

    QDate da=QDate::fromString(dd,"dd-MM-yyyy");
    well this line gives error saying "QDate(Invalid)"
    so how can i change my format???

    J 1 Reply Last reply 5 Feb 2019, 12:41
    1
    • J JonB
      5 Feb 2019, 12:46

      @Vineela
      As @jsulm has just stated, you now have an issue about your date output format not the input you converted from. Look through the documentation of http://doc.qt.io/qt-5/qdate.html#toString, i.e. toString() not fromString().

      V Offline
      V Offline
      Vineela
      wrote on 5 Feb 2019, 12:54 last edited by
      #7

      @JonB , @jsulm , @VRonin thanks

                           QString dd ="2018-08-01";
                           qDebug() << "ddddd" << dd;
                           QDate da=QDate::fromString(dd,"yyyy-MM-dd");
                           QString dw = da.toString("dd-MM-yyyy");
      

      well this is solved like this :D

      1 Reply Last reply
      4
      • V Vineela
        5 Feb 2019, 12:38

        Converting QString date format from "yyyy-MM-dd" to "dd-MM-yyyy"

        this is my QString
        QString dd = "2018-08-01";

        QDate da=QDate::fromString(dd,"dd-MM-yyyy");
        well this line gives error saying "QDate(Invalid)"
        so how can i change my format???

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 5 Feb 2019, 12:41 last edited by
        #2

        @Vineela said in Converting Date Format:

        QDate da=QDate::fromString(dd,"dd-MM-yyyy");

        Shouldn't it be

        QDate da=QDate::fromString(dd,"yyyy-MM-dd");
        

        ?
        Your string is "2018-08-01" and not "01-08-2018"...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        V 1 Reply Last reply 5 Feb 2019, 12:44
        3
        • V Offline
          V Offline
          VRonin
          wrote on 5 Feb 2019, 12:41 last edited by
          #3

          fromString wants the format you are converting from ,not to
          QDate da=QDate::fromString(dd,Qt::ISODate); (yyyy-MM-dd is the ISO-8601 format)

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2
          • J jsulm
            5 Feb 2019, 12:41

            @Vineela said in Converting Date Format:

            QDate da=QDate::fromString(dd,"dd-MM-yyyy");

            Shouldn't it be

            QDate da=QDate::fromString(dd,"yyyy-MM-dd");
            

            ?
            Your string is "2018-08-01" and not "01-08-2018"...

            V Offline
            V Offline
            Vineela
            wrote on 5 Feb 2019, 12:44 last edited by
            #4

            @jsulm oh yes that was so silly thanks but my output now is 01/08/18 this ,what abt last one yyyy ?

            J J 2 Replies Last reply 5 Feb 2019, 12:45
            0
            • V Vineela
              5 Feb 2019, 12:44

              @jsulm oh yes that was so silly thanks but my output now is 01/08/18 this ,what abt last one yyyy ?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 5 Feb 2019, 12:45 last edited by jsulm 2 May 2019, 12:46
              #5

              @Vineela You can convert your date to whatever string you want.
              http://doc.qt.io/qt-5/qdate.html#toString-2

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • V Vineela
                5 Feb 2019, 12:44

                @jsulm oh yes that was so silly thanks but my output now is 01/08/18 this ,what abt last one yyyy ?

                J Offline
                J Offline
                JonB
                wrote on 5 Feb 2019, 12:46 last edited by JonB 2 May 2019, 12:48
                #6

                @Vineela
                As @jsulm has just stated, you now have an issue about your date output format not the input you converted from. Look through the documentation of http://doc.qt.io/qt-5/qdate.html#toString, i.e. toString() not fromString().

                V 1 Reply Last reply 5 Feb 2019, 12:54
                2
                • J JonB
                  5 Feb 2019, 12:46

                  @Vineela
                  As @jsulm has just stated, you now have an issue about your date output format not the input you converted from. Look through the documentation of http://doc.qt.io/qt-5/qdate.html#toString, i.e. toString() not fromString().

                  V Offline
                  V Offline
                  Vineela
                  wrote on 5 Feb 2019, 12:54 last edited by
                  #7

                  @JonB , @jsulm , @VRonin thanks

                                       QString dd ="2018-08-01";
                                       qDebug() << "ddddd" << dd;
                                       QDate da=QDate::fromString(dd,"yyyy-MM-dd");
                                       QString dw = da.toString("dd-MM-yyyy");
                  

                  well this is solved like this :D

                  1 Reply Last reply
                  4

                  1/7

                  5 Feb 2019, 12:38

                  • Login

                  • Login or register to search.
                  1 out of 7
                  • First post
                    1/7
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved