Zope Date format conversion problem
Dear All, I am facing problems while converting American date format(MM/DD/YYYY) to MySQL date format(YYYY/MM/DD). Here I'm giving the code I'm using, please suggest where I have gone wrong and how to rectify. test_front: <dtml-var la_header> <form name="data" ACTION="test_back" METHOD="POST"> <input type="text" name="date2" size="15" value=""> <input type=submit name=submit value=update> </form> test_back: <dtml-if "submit=='update'"> <dtml-if "date2==_.None"> <dtml-var date2 null=""> <dtml-else> <dtml-call "REQUEST.set('date2',date2.strftime('%Y/%m/%d'))"> <dtml-var date2 null=""> </dtml-if> </dtml-if> <dtml-var date2> -- Thanks & Regards Praveen Kumar SoftPro Systems Ltd
On Wed, 2003-10-08 at 23:15, K. Praveen Kumar wrote:
<input type="text" name="date2" size="15" value=""> <snip> <dtml-call "REQUEST.set('date2',date2.strftime('%Y/%m/%d'))">
Unless I'm misreading, your problem is that date2 is a string and therefore doesn't have a strftime() method. But your traceback probably told you *that* much. :-) To fix this, convert the string to a date using strptime(). If you're on Win32, you may not have strptime() and may need to find one of the many third party implementations available online. HTH, Dylan
or use name="date2:date" in the input form. -aj --On Mittwoch, 8. Oktober 2003 23:25 Uhr -0700 Dylan Reinhardt <zope@dylanreinhardt.com> wrote:
On Wed, 2003-10-08 at 23:15, K. Praveen Kumar wrote:
<input type="text" name="date2" size="15" value=""> <snip> <dtml-call "REQUEST.set('date2',date2.strftime('%Y/%m/%d'))">
Unless I'm misreading, your problem is that date2 is a string and therefore doesn't have a strftime() method. But your traceback probably told you *that* much. :-)
To fix this, convert the string to a date using strptime(). If you're on Win32, you may not have strptime() and may need to find one of the many third party implementations available online.
HTH,
Dylan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Wed, 2003-10-08 at 23:33, Andreas Jung wrote:
or use name="date2:date" in the input form.
I'm not a big fan of putting the client in charge of declaring your data types. But I'll spare everyone another iteration of *that* rant. :-) Thinking about it some more, if you *know* you just want to translate one format to another, a two-line Python script will do the trick: --------- # date2 passed in as a parameter # 'MM/DD/YYYY' -> 'YYYY/MM/DD' d = date2.split('/') return '/'.join(d[2],d[0],d[1]) --------- If you want to do additional validation or formatting, obviously you'll need more than this. HTH, Dylan
Dylan Reinhardt wrote:
To fix this, convert the string to a date using strptime(). If you're on Win32, you may not have strptime() and may need to find one of the many third party implementations available online.
Urm? Zope has the DateTime class for this: x = DateTime('2000/12/01') cheers, Chris
K. Praveen Kumar wrote:
<dtml-var la_header>
well, you're using DTML which is pretty silly, should be using ZPT for presentation...
<form name="data" ACTION="test_back" METHOD="POST"> <input type="text" name="date2" size="15" value="">
try changing that to: <input type="text" name="date2:date" size="15" value="">
test_back:
<dtml-if "submit=='update'">
<dtml-if "date2==_.None"> <dtml-var date2 null=""> <dtml-else> <dtml-call "REQUEST.set('date2',date2.strftime('%Y/%m/%d'))"> <dtml-var date2 null=""> </dtml-if>
</dtml-if>
This lot should really be a python script... Chris
HI All, When I try it it is working fine but While updating it is giving error. If some of my date fields are NULL and try to update the values then it is giving the following ERROR: Error Type: Invalid Date-Time String Error Value: Location: My Scripts are: Front: <input type="text" name="date1:date" size="15" value="<dtml-if "Child_Enrollment_Date==_.None"><dtml-var Child_Enrollment_Date null=""><dtml-else><dtml-call "REQUEST.set('Child_Enrollment_Date1',Child_Enrollment_Date.strftime('%m/%d/%Y'))"><dtml-var Child_Enrollment_Date1 null=""></dtml-if>"> <input type="text" name="date2:date" size="15" value="<dtml-if "Child_Enrollment_Date==_.None"><dtml-var Child_Enrollment_Date null=""><dtml-else><dtml-call "REQUEST.set('Child_Enrollment_Date1',Child_Enrollment_Date.strftime('%m/%d/%Y'))"><dtml-var Child_Enrollment_Date1 null=""></dtml-if>"> Back: <dtml-call "REQUEST.set('date1',date1.strftime('%Y/%m/%d'))"> <dtml-if "date2==''"> <dtml-call "REQUEST.set('date2',_.None)"> <dtml-else> <dtml-call "REQUEST.set('date2',date2.strftime('%Y/%m/%d'))"> </dtml-if> Where I am filling date1 field and not filling date2 field. While submitting the form It is giving the above error. How can I rectify this. How can I validate if date field is not filled then how can I submit that? Any suggestions will be greatly appreciated. Thanks & Regards Praveen On Thu, 2003-10-09 at 19:33, Chris Withers wrote:
K. Praveen Kumar wrote:
<dtml-var la_header>
well, you're using DTML which is pretty silly, should be using ZPT for presentation...
<form name="data" ACTION="test_back" METHOD="POST"> <input type="text" name="date2" size="15" value="">
try changing that to:
<input type="text" name="date2:date" size="15" value="">
test_back:
<dtml-if "submit=='update'">
<dtml-if "date2==_.None"> <dtml-var date2 null=""> <dtml-else> <dtml-call "REQUEST.set('date2',date2.strftime('%Y/%m/%d'))"> <dtml-var date2 null=""> </dtml-if>
</dtml-if>
This lot should really be a python script...
Chris
-----------------------SOFTPRO DISCLAIMER------------------------------ Information contained in this E-MAIL and any attachments are confidential being proprietary to SOFTPRO SYSTEMS is 'privileged' and 'confidential'. If you are not an intended or authorised recipient of this E-MAIL or have received it in error, You are notified that any use, copying or dissemination of the information contained in this E-MAIL in any manner whatsoever is strictly prohibited. Please delete it immediately and notify the sender by E-MAIL. In such a case reading, reproducing, printing or further dissemination of this E-MAIL is strictly prohibited and may be unlawful. SOFTPRO SYSYTEMS does not REPRESENT or WARRANT that an attachment hereto is free from computer viruses or other defects. The opinions expressed in this E-MAIL and any ATTACHEMENTS may be those of the author and are not necessarily those of SOFTPRO SYSTEMS. ------------------------------------------------------------------------
K. Praveen Kumar wrote at 2003-10-14 17:57 +0530:
When I try it it is working fine but While updating it is giving error. If some of my date fields are NULL and try to update the values then it is giving the following ERROR:
Error Type: Invalid Date-Time String Error Value:
The empty string and "None" are not valid Date-Time's. You need application specific handling of such invalid dates. Dieter
participants (5)
-
Andreas Jung -
Chris Withers -
Dieter Maurer -
Dylan Reinhardt -
K. Praveen Kumar