Converting Date Format
-
wrote on 5 Feb 2019, 12:38 last edited by
Converting QString date format from "yyyy-MM-dd" to "dd-MM-yyyy"
this is my QString
QString dd = "2018-08-01";QDate da=QDate::fromString(dd,"dd-MM-yyyy");
well this line gives error saying "QDate(Invalid)"
so how can i change my format??? -
@Vineela
As @jsulm has just stated, you now have an issue about your date output format not the input you converted from. Look through the documentation of http://doc.qt.io/qt-5/qdate.html#toString, i.e.toString()
notfromString()
. -
Converting QString date format from "yyyy-MM-dd" to "dd-MM-yyyy"
this is my QString
QString dd = "2018-08-01";QDate da=QDate::fromString(dd,"dd-MM-yyyy");
well this line gives error saying "QDate(Invalid)"
so how can i change my format???@Vineela said in Converting Date Format:
QDate da=QDate::fromString(dd,"dd-MM-yyyy");
Shouldn't it be
QDate da=QDate::fromString(dd,"yyyy-MM-dd");
?
Your string is "2018-08-01" and not "01-08-2018"... -
wrote on 5 Feb 2019, 12:41 last edited by
fromString
wants the format you are converting from ,not to
QDate da=QDate::fromString(dd,Qt::ISODate);
(yyyy-MM-dd
is the ISO-8601 format) -
@Vineela said in Converting Date Format:
QDate da=QDate::fromString(dd,"dd-MM-yyyy");
Shouldn't it be
QDate da=QDate::fromString(dd,"yyyy-MM-dd");
?
Your string is "2018-08-01" and not "01-08-2018"... -
@jsulm oh yes that was so silly thanks but my output now is 01/08/18 this ,what abt last one yyyy ?
Lifetime Qt Championwrote on 5 Feb 2019, 12:45 last edited by jsulm 2 May 2019, 12:46@Vineela You can convert your date to whatever string you want.
http://doc.qt.io/qt-5/qdate.html#toString-2 -
@jsulm oh yes that was so silly thanks but my output now is 01/08/18 this ,what abt last one yyyy ?
wrote on 5 Feb 2019, 12:46 last edited by JonB 2 May 2019, 12:48@Vineela
As @jsulm has just stated, you now have an issue about your date output format not the input you converted from. Look through the documentation of http://doc.qt.io/qt-5/qdate.html#toString, i.e.toString()
notfromString()
. -
@Vineela
As @jsulm has just stated, you now have an issue about your date output format not the input you converted from. Look through the documentation of http://doc.qt.io/qt-5/qdate.html#toString, i.e.toString()
notfromString()
.
1/7