Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946
[Solved] QDate::fromString() dateformat restrictions.
I want to parse an incomming text to a date format.
But since I live in Belgium, people often use format dd/mm/yyyy.
It seems that Qt, can't handle this kind of date.
Are there any restrictings on QDate::fromString()?
If yes, please tell me where I can find them.
Thanks in advance.
Suths last edited by
Yes it can you need to tell it the format though so something like QDate::fromString("22112012", "dMyyyy"); that should do the trick read here http://doc.qt.digia.com/qt/qdate.html#fromString for further info.
Nosf last edited by
QDate converted_date(QDate::fromString(str, "dd/MM/yyyy"));@
Watch the case MM is months while mm is minutes
I think I phrased my question wrong.
This is what a want to achieve:
@birthdate = (QDate::fromString(23/11/2012, "yyyy-MM-dd").isValid() ? QDate::fromString(23/11/2012, "yyyy-MM-dd") : QDate(1970,01,01));@
Birthdate has to be the format yyyy-MM-dd
So I get an inputdate of dd/MM/yyyy and I want to get yyyy-MM-dd into my database.
Is it possible to be not possible? Do you have to split the date yourself?
Nosf last edited by
is the input format constant?
if so just use
If you don't there isn't a foolproof way of getting it correctly. If this is an input from the user use a validator to validate their input and check the format is right or do a string replace with regex
@variable = variable.replace(QRegExp("[/, ]"), "-");
flaviomarcio last edited by
I have it and it worked well
QString Tsysfun::SSQLDat(QDateTime v)
const sformat="yyyy-MM-dd hh:mm:ss";
[Edit: Added @ tags to code -- mlong]
Thanks Nosf, it the closest I'm going to get to a solution.
The input format isn't constant.
The user get to choose the format, but I don't know what formats that can be.
But for now it's 'solved'.
If it's solved, be sure and edit your initial post and change the title to add [Solved]. Thanks!