How to convert date format into string in BlackBerry 10 - c++

I need to get date and time of received and sent messages . I used deviceTimestamp() method of Message class but this returns obj of QDateTime but I want this in String . So could anyone please tell me how should I do this or any other way of getting message time and date ?

Once you obtain your QDateTime, can't use the toString() method?
https://qt-project.org/doc/qt-5.0/qtcore/qdatetime.html#toString
QString dateString = yourQDateTime.toString("MM-dd-yyyy hh:mm");

Related

How to put a current date in QLabel in digits?

I have a problem with convert a current date.
I want to put a current date in a QLabel but i can't put a QDate type.
QDate today;
today=QDate::currentDate();
datamiasto->setText("Data wystawienia: "+today+", xyz");
I can put it when i convert it to string but when i do it date is not in digits.
How can i put a digit date in a QLabel ?
Try this:
QDateTime dateTime = dateTime.currentDateTime();
QString dateTimeString = dateTime.toString("yyyy-MM-dd_hh-mm-ss");
QDateTime::toString(const QString &format) : Returns the datetime as a string. The format parameter determines the format of the result string. (give your custom format to the function)
QDateTime::currentDateTime() : Returns the current datetime, as reported by the system clock, in the local time zone.

informatica datetime datatype format

I want to convert the string 20160101000000 into datetime format using expression. I have used below date function
TO_DATE(PERIOD_END_DATE),'MM/DD/YYYY HH24:MI:SS')
But my table file is not loading. My session and workflow gets succeed. My target and source is also flatfile.
I want to change the string 20160101000000 into MM/DD/YYYY HH24:MI:SS for loading data into my target table.
You need to give exact format that looks so that to_date function can understand that format and converts it into date.
TO_DATE(PERIOD_END_DATE,'YYYYMMDDHH24MISS')
So here your date looks like YYYYMMDDHH24MISS (20160101000000).
There is often confusion with the TO_DATE function... it is in fact for converting a string into a date and the function itself is to describe the pattern of the incoming date. Now if you want to convert a date field to a specified date format you must use TO_CHAR

Converting time stamp in informatica to date

I want to display the time stamp in following format '2011-04-22 10:41:57.000' to date as '04/22/2011' but when it convert it to following form TO_DATE(TO_CHAR(Date), 'MM/DD/YYYY HH24:MI:SS') it is displaying as null.
I am planning to use substring after the conversion
Can someone please tell me where i am going wrong?
You can simply do TO_CHAR(Date, 'MM/DD/YYYY')
i used 'TO_DATE(TO_CHAR(Date), 'MM/DD/YYYY HH24:MI:SS')' and later 'SUBSTR(Date_V,1,11)' and i got required output

How to convert QString to QDate in specific format?

I have a QDateEdit in my GUI from which I convert the QDate to QString and add it to my database. The QString date is saved in the database in this format: 20/12/2015.
In case a user want to edit the date, then I need to show the date on the QDateEdit field on the GUI again. Hence, I need to fetch the database, bring back the date (which is in QString format) and convert it to QDate back again in order to put it on the QDateEdit field on the GUI.
However, I cannot manage to convert that QString format (i.e.: 20/12/2015) to QDate using the following:
QString date_string_on_db = "20/12/2015";
QDate Date;
Date.fromString(date_string_on_db,"dd/MM/YYYY");
The Date is always returning invalid.
what should I do ?
First of all, the format string should be dd/MM/yyyy. Qt documentation for the QDate class says that yyyy is recognized as a four digit year number.
Second of all, fromString is a static function that returns a new QDate. Currently, the return value of that function is discarded : it is not written back into the Date variable, as you might think. The complete correct code should therefore look like this :
QString date_string_on_db = "20/12/2015";
QDate Date = QDate::fromString(date_string_on_db,"dd/MM/yyyy");

Qt - GUI Database programming

I am using Qt GUI to save data in MySQL using C++.
I am using QDateTimeEdit widget for this. Whatever the value changed by user in GUI of QDateTimeEdit, it should be inserted in MySQL.
Can anyone tell me how to do that?
How to access value from QDateTimeEdit and converting it in proper format like QString and using MySQL query inserting it into database?
An alternative is not to convert it to a QString but let the driver do that for you. If you expect some precision in the conversion some cases this might be better, other cases it can be worse:
QDateTime date = ui->dateTimeEdit->dateTime();
QSqlQuery query(myDatabase);
query.prepare("INSERT INTO my_table (id, date) "
" VALUES (:id, :date)");
query.bindValue(":id", 1001);
query.bindValue(":date", date);
query.exec();
The QSqlQuery::bindValue() function will take the QDateTime and pass it through as a QVariant and then the driver should know how to convert a QVariant::DateTime to the correct string that the database understands.
About second part "how to access value":
You somehow in code created object of QDateTimeEdit and place it on some layout. Typically it will be pointer with name for example mpDTPicker.
QDateTimeEdit * mpDTPicker = new QDateTimeEdit();
//place mpDTPicker on layout.
For access current time we need use method dateTime:
//User actions with date -> emitted signal -> execute slot with our logic
{
QDateTime momentum = mpDTPicker->dateTime();
// So here we need convert QDateTime to QString and we will use [toString Method](http://doc.qt.io/qt-4.8/qdatetime.html#toString)
QString result_string = momentum.toString("dd:mm:yy");
QDebug() << result_string;
}
So that is all about converting QDateTime to QString.
About first part of Question how to get that user changed value of DateTimeEdit is total another question.
And about third part how to store it in mysql database everything depended on structure of your table. But typicaly it can be solved with simple query:
QSqlQuery query;
QString mQuerry = "INSERT INTO mytable (id, date) VALUES (0, \"" +result_string "\" )";
query.exec(mQuerry);
And please READ DOCS especial when them so cool :)