DateTime: Get DateTime-Objekt from german dateformat %d.%m.%Y
Hi, i have a litte problem to insert my german dateformat into my SQL-Database, because I must convert it to ISO-Format. I try datum=_.DateTime (wiedervorlage).ISO()) but day and month ar interchanged. How can I convert my datestring '1.3.2005' to '2005-03-01'? Thanks, Patrick
--On Donnerstag, 3. März 2005 11:49 Uhr +0100 Patrick Ulmer <ulmer@truckport.de> wrote:
Hi,
i have a litte problem to insert my german dateformat into my SQL-Database, because I must convert it to ISO-Format. I try
datum=_.DateTime (wiedervorlage).ISO())
but day and month ar interchanged.
That's why it is called ISO format which is defined in the way you see it.
How can I convert my datestring '1.3.2005' to '2005-03-01'?
Look at the DateTime API -> somedate.strftime(formatstring) -aj
i have a litte problem to insert my german dateformat into my SQL-Database, because I must convert it to ISO-Format. I try
datum=_.DateTime (wiedervorlage).ISO())
but day and month ar interchanged.
That's why it is called ISO format which is defined in the way you see it.
No. this is not the Problem. '1.3.2005' (D/M/Y) ist converted to '2005-01-03' but for germany '2005-03-01' is correct.
How can I convert my datestring '1.3.2005' to '2005-03-01'?
Look at the DateTime API -> somedate.strftime(formatstring)
I know this function but my problem is to get "somedate" from my german formated (D/M/Y) datestring. Thanks, Patrick
Hi Patrick, Patrick Ulmer wrote:
i have a litte problem to insert my german dateformat into my SQL-Database, because I must convert it to ISO-Format. I try
datum=_.DateTime (wiedervorlage).ISO())
but day and month ar interchanged.
That's why it is called ISO format which is defined in the way you see it.
No. this is not the Problem. '1.3.2005' (D/M/Y) ist converted to '2005-01-03' but for germany '2005-03-01' is correct.
So the ISO function is working fine, but it mis-interprets your D/M/Y input as M/D/Y - e.g. it thinks it is a US format date.
How can I convert my datestring '1.3.2005' to '2005-03-01'?
Look at the DateTime API -> somedate.strftime(formatstring)
I know this function but my problem is to get "somedate" from my german formated (D/M/Y) datestring.
Where does this string originate? -- Regards, PhilK Email: phil@xfr.co.uk / Voicemail & Facsimile: 07092 070518 "When the going gets weird, the weird turn pro." -- Hunter S. Thompson 1937-2005. RIP.
Hi,
i have a litte problem to insert my german dateformat into my SQL-Database, because I must convert it to ISO-Format. I try
datum=_.DateTime (wiedervorlage).ISO())
but day and month ar interchanged.
That's why it is called ISO format which is defined in the way you see it.
No. this is not the Problem. '1.3.2005' (D/M/Y) ist converted to '2005-01-03' but for germany '2005-03-01' is correct.
So the ISO function is working fine, but it mis-interprets your D/M/Y input as M/D/Y - e.g. it thinks it is a US format date.
Yes, that's my problem.
How can I convert my datestring '1.3.2005' to '2005-03-01'?
Look at the DateTime API -> somedate.strftime(formatstring)
I know this function but my problem is to get "somedate" from my german formated (D/M/Y) datestring.
Where does this string originate?
From my html-form entered by users.
Hi Patrick, Patrick Ulmer wrote:
Where does this string originate?
From my html-form entered by users.
Aha - well, I use Formulator for forms, so if the form has validated I know I can safely use string manipulation to assemble the DD-MM-YYYY subfields into an ISO date. Assuming you are validating this input prior to trying to stuff it in the dB (you should!), it should be possible to create the ISO-formatted string as you validate. If you want an example of how I do this with Formulator (which I find v. useful!), I'd be happy to send one... HTH -- Regards, PhilK Email: phil@xfr.co.uk / Voicemail & Facsimile: 07092 070518 "When the going gets weird, the weird turn pro." -- Hunter S. Thompson 1937-2005. RIP.
Patrick Ulmer wrote:
So the ISO function is working fine, but it mis-interprets your D/M/Y input as M/D/Y - e.g. it thinks it is a US format date.
Yes, that's my problem.
There is an option in zope.conf to do with international date formats, you may solve your problem by fiddling with this... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Hi,
i have a litte problem to insert my german dateformat into my SQL-Database, because I must convert it to ISO-Format. I try
datum=_.DateTime (wiedervorlage).ISO())
but day and month ar interchanged.
How can I convert my datestring '1.3.2005' to '2005-03-01'?
One solution is to put this in an external method: from time import strftime, strptime print strftime("%Y-%m-%d", strptime ("1.3.2005", "%d.%m.%Y")) Thanks, Patrick
--On Donnerstag, 3. März 2005 14:36 Uhr +0100 Patrick Ulmer <ulmer@truckport.de> wrote:
Hi,
i have a litte problem to insert my german dateformat into my SQL-Database, because I must convert it to ISO-Format. I try
datum=_.DateTime (wiedervorlage).ISO())
but day and month ar interchanged.
How can I convert my datestring '1.3.2005' to '2005-03-01'?
One solution is to put this in an external method:
from time import strftime, strptime print strftime("%Y-%m-%d", strptime ("1.3.2005", "%d.%m.%Y"))
Why do you make it so complicated? And why don't you modify your SQL query so that it returns your date in a format e.g. YYYYDDMM can can be parsed by DateTime out-of-the-box? This would be the most straight forward way to go. -aj
Hi,
i have a litte problem to insert my german dateformat into my SQL-Database, because I must convert it to ISO-Format. I try datum=_.DateTime (wiedervorlage).ISO()) but day and month ar interchanged. How can I convert my datestring '1.3.2005' to '2005-03-01'?
One solution is to put this in an external method: from time import strftime, strptime print strftime("%Y-%m-%d", strptime ("1.3.2005", "%d.%m.%Y"))
Why do you make it so complicated? And why don't you modify your SQL query so that it returns your date in a format e.g. YYYYDDMM can can be parsed by DateTime out-of-the-box? This would be the most straight forward way to go.
I want to insert the string an a datefield and the needed SQL-function |STR_TO_DATE(/|str|/,/|format|/) is only available in MySQL 4.1.1 but I use 4.0.x. To get the wished format from my select-statement is not the problem.|
participants (4)
-
Andreas Jung -
Chris Withers -
Patrick Ulmer -
Philip Kilner