Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Invalid DateTime Error

Invalid DateTime Error

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 605 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.
  • M Offline
    M Offline
    Madesh R
    wrote on last edited by
    #1

    Hi ,

    I am trying to convert a string to qDateTime. But every time , i'm getting Invalid() datetime errror.Below is my code snippet.Please someone let me know how to fix it
    QString lastdate = "12-06-2019 1:30"
    QString date = lastdate ;
    QString format = "dd-MM-yyyy HH:mm";
    qDebug()<<"date:"<<lastdate;
    qDebug()<<"format:"<<format;
    QDateTime dateTime = QDateTime::fromString(date, format);
    bool isItValid = dateTime.isValid();

    Thank you

    J.HilkJ 1 Reply Last reply
    0
    • M Madesh R

      Hi ,

      I am trying to convert a string to qDateTime. But every time , i'm getting Invalid() datetime errror.Below is my code snippet.Please someone let me know how to fix it
      QString lastdate = "12-06-2019 1:30"
      QString date = lastdate ;
      QString format = "dd-MM-yyyy HH:mm";
      qDebug()<<"date:"<<lastdate;
      qDebug()<<"format:"<<format;
      QDateTime dateTime = QDateTime::fromString(date, format);
      bool isItValid = dateTime.isValid();

      Thank you

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Madesh-R

      HH:mm

      expects a leading 0 for the hours.
      12-06-2019 1:30 clearly has no leading 0 -> Format error


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      M 1 Reply Last reply
      2
      • J.HilkJ J.Hilk

        @Madesh-R

        HH:mm

        expects a leading 0 for the hours.
        12-06-2019 1:30 clearly has no leading 0 -> Format error

        M Offline
        M Offline
        Madesh R
        wrote on last edited by
        #3

        @J.Hilk
        Thank you so much . It solved the problem :)

        1 Reply Last reply
        0

        • Login

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