View Full Version : Helppp!!! how to change date format from dd-MM-yyyy to yyyy-MM-dd:confused:
wiralim
10th April 2012, 09:51
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...
mentalmushroom
10th April 2012, 10:18
QDateTime::fromString
QDateTime::toString
wiralim
10th April 2012, 12:16
I've tried the 2 methods you mention above. but it can't be converted. this is the code :
QDateTime date;
date = QDateTime::fromString(ui->lineEditLahir->text(),"yyyyMMdd");
qDebug()<<date;
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.
mentalmushroom
10th April 2012, 12:25
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.
wiralim
10th April 2012, 12:44
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 :
7574
this is the database format :
7575
mentalmushroom
10th April 2012, 13:02
QDateTime dt1 = QDateTime::fromString("12-12-2012", "dd-MM-yyyy");
qDebug() << dt1.toString("yyyy-MM-dd");
wiralim
10th April 2012, 13:08
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 ?
mentalmushroom
10th April 2012, 14:02
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.
wiralim
10th April 2012, 16:23
Thx it solved...
krishnap2w2
21st November 2014, 06:29
I have encountered a similar problem with Screen Update. I resolved it. I attachment has the solution with screenshots.
10755
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.