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

Converting Date Format

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 13.7k 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.
  • VineelaV Offline
    VineelaV Offline
    Vineela
    wrote on 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???

    jsulmJ 1 Reply Last reply
    1
    • JonBJ JonB

      @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().

      VineelaV Offline
      VineelaV Offline
      Vineela
      wrote on 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
      • VineelaV Vineela

        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???

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on 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

        VineelaV 1 Reply Last reply
        3
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on 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
          • jsulmJ jsulm

            @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"...

            VineelaV Offline
            VineelaV Offline
            Vineela
            wrote on 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 ?

            jsulmJ JonBJ 2 Replies Last reply
            0
            • VineelaV Vineela

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

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #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
              • VineelaV Vineela

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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #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().

                VineelaV 1 Reply Last reply
                2
                • JonBJ JonB

                  @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().

                  VineelaV Offline
                  VineelaV Offline
                  Vineela
                  wrote on 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

                  • Login

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