Results 1 to 10 of 10

Thread: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

  1. #1
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    I have a problem...

    my database only want to receive the yyyy-mm-dd format for saving the data, but the user wants to input the date format in dd-mm-yyyy. i have set my QLineedit become ui->lineEditDate->setInputMask("00-00-0000"); (for user requirements). the problem is : how can i change the data that user input (dd-mm-yyyy) become yyyy-MM-dd for being accept by the database ???

    Thx...

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    QDateTime::fromString
    QDateTime::toString

  3. #3
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    I've tried the 2 methods you mention above. but it can't be converted. this is the code :

    Qt Code:
    1. QDateTime date;
    2. date = QDateTime::fromString(ui->lineEditLahir->text(),"yyyyMMdd");
    3. qDebug()<<date;
    To copy to clipboard, switch view to plain text mode 

    this is the build result : QDateTime("")

    QDatetime::toString() is not function for me, because what i'm trying to do is convert a String from line edit where user input it. the string format is like a date format, eg : 13-01-2012 (dd-MM-yyyy) and i want to convert the string into yyyy-MM-dd for storing it on database.

  4. #4
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    At first, let's clear up what kind of data do you want to input and how this should look like in the database. Just show a sample.

  5. #5
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    Database (MySQL) only accept data in date yyyy-mm-dd format, it couldn't accept the dd-mm-yyyy format where i have a lineedit which takes user input and i have set input mask to the line edit (just like the picture below). So, in order to save it, i must convert it to the database acceptance format : yyyy-mm-dd. The question is : how can i convert the dd-mm-yyyy format (which i get from a lineedit) to the database acceptance format ?

    this is the data :
    Untitled.jpg

    this is the database format :
    Untitled.jpg
    Last edited by wiralim; 10th April 2012 at 13:06.

  6. #6
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    QDateTime dt1 = QDateTime::fromString("12-12-2012", "dd-MM-yyyy");
    qDebug() << dt1.toString("yyyy-MM-dd");

  7. #7
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    What if the user change the date on the lineedit ???

    everytime user input to the lineedit must be convert it, are the above code can do that ?

  8. #8
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    as far as i understood, the database is updated when a user clicks submit. if so, connect clicked signal to some submit slot and do the conversion in that slot.

  9. The following user says thank you to mentalmushroom for this useful post:

    wiralim (10th April 2012)

  10. #9
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    Thx it solved...

  11. #10
    Join Date
    Nov 2014
    Posts
    1
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:

    I have encountered a similar problem with Screen Update. I resolved it. I attachment has the solution with screenshots.

    How to Change YYYYMMDD Format.pdf

Similar Threads

  1. Regular Expression YYYY-MM-DD and YYYY MM DD
    By kedibone in forum Newbie
    Replies: 2
    Last Post: 3rd August 2019, 09:45
  2. Regular Expression for QDate [YYYY/MM/DD] format
    By bera82 in forum Qt Programming
    Replies: 6
    Last Post: 3rd August 2019, 09:40
  3. Replies: 2
    Last Post: 3rd June 2011, 07:39
  4. QDateEdit Init Value ' / /yyyy'
    By visor_ua in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2007, 12:26
  5. Replies: 7
    Last Post: 17th November 2007, 11:33

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.