Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Spanish
  4. Comparar Fechas
Forum Updated to NodeBB v4.3 + New Features

Comparar Fechas

Scheduled Pinned Locked Moved Solved Spanish
2 Posts 2 Posters 766 Views 1 Watching
  • 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.
  • ColomanC Offline
    ColomanC Offline
    Coloman
    wrote on last edited by
    #1

    Hola! He intentado compara fechas a partir de un QDateEdit sin exito, el codigo es el siguiente

    QString fecha_principio,fecha_fin;

    fecha_principio=ui->d_vdesde->text().trimmed();
    fecha_fin=ui->d_vhasta->text().trimmed();

    QDate Date_inicio = QDate::fromString(fecha_principio,"dd/MM/yyyy");
    QDate Date_fin = QDate::fromString(fecha_fin,"dd/MM/yyyy");

    if((Date_inicio==(Date_fin))||(Date_inicio.operator>(Date_fin)))

    { Mensaje de error si se cumple esta condicion}
    else
    {lo que necesito que haga}

    Nunca logro salir del mensaje de error independienteme lo que coloque en las fechas
    En la primera comparacion coloque == pero tambien he probado .operator==

    Pablo J. RoginaP 1 Reply Last reply
    0
    • ColomanC Coloman

      Hola! He intentado compara fechas a partir de un QDateEdit sin exito, el codigo es el siguiente

      QString fecha_principio,fecha_fin;

      fecha_principio=ui->d_vdesde->text().trimmed();
      fecha_fin=ui->d_vhasta->text().trimmed();

      QDate Date_inicio = QDate::fromString(fecha_principio,"dd/MM/yyyy");
      QDate Date_fin = QDate::fromString(fecha_fin,"dd/MM/yyyy");

      if((Date_inicio==(Date_fin))||(Date_inicio.operator>(Date_fin)))

      { Mensaje de error si se cumple esta condicion}
      else
      {lo que necesito que haga}

      Nunca logro salir del mensaje de error independienteme lo que coloque en las fechas
      En la primera comparacion coloque == pero tambien he probado .operator==

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @Coloman si usas QDateEdit el método date() devuelve un QDate directamente, no necesitarías la conversión.

      Hice un pequeño ejemplo con 2 QDateEdit y un QPushButton, cuando hago click en el botón se ejecuta este métdodo, y la comparación sale de acuerdo a lo esperado:

      void MainWindow::on_btnCompare_clicked() {
          ui->dateFrom->date();
          ui->dateTo->date();
      
          if (ui->dateFrom->date() >= ui->dateTo->date()) {
              qDebug() << "Not Ok: dateFrom >= dateTo";
          } else {
              qDebug() << "Ok: dateFrom < dateTo";
          }
      }
      

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2

      • Login

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