[Zope] dd/mm/yyyy date into MySQL

Capesius, Alan CapesiusA@Sysmex.com
Wed, 16 May 2001 10:37:33 -0500


Assuming its a string,

I use this code to convert from yyyymmdd format to mm/dd/yy form.
<dtml-let x="_.str(date)[4:6] + '/' + _.str(date)[6:8] + '/' +
_.str(date)[2:4]">
   <dtml-return x>
</dtml-let >


Use a similar technique of splitting and reassembling the string to go the
other way

Name: dateswap
(untested)
<dtml-let x="_.str(date)[6:10] + '/' + _.str(date)[0:5]>
   <dtml-return x>
</dtml-let >

Call this from your DTML with <dtml-var "dateswap(date=formdate)">

You should validate the date format from the form or catch conversion errors
in case the user enters a bad format.
This code does not check for invalid dates (feb 35th, etc.)


http://twsite.bizland.com/zopetips.htm


>>>-----Original Message-----
>>>From: Sion Morris [mailto:s.morris@bangor.ac.uk]
>>>Sent: Wednesday, May 16, 2001 4:18 AM 
>>>To: zope@zope.org
>>>Subject: [Zope] dd/mm/yyyy date into MySQL
>>>
>>>
>>>Hi,
>>>
>>>What would be the best way to take a date in the format 
>>>'dd/mm/yyyy' from a
>>>form and insert it into a date field in a MySQL table, which 
>>>takes the format
>>>yyyy/mm/dd?
>>>
>>>I could have seperate fields for day, month and year and piece them
>>>together before inserting them in the table. But, is it 
>>>possible to take a
>>>complete date, and change it format before inserting it in a 
>>>MySQL table?
>>>Having looked at the Zope Book nothing obvious jumped out.
>>>
>>>Regards,
>>>
>>>Sion
>>>
>>>--
>>>Computer Support
>>>Sion Morris
>>>School of Psychology                       Ysgol Seicoleg
>>>University of Wales, Bangor                Prifysgol Cymru Bangor
>>>Tel: 01248 382469
>>>Fax: 01248 382599
>>>
>>>
>>>
>>>_______________________________________________
>>>Zope maillist  -  Zope@zope.org
>>>http://lists.zope.org/mailman/listinfo/zope
>>>**   No cross posts or HTML encoding!  **
>>>(Related lists - 
>>> http://lists.zope.org/mailman/listinfo/zope-announce
>>> http://lists.zope.org/mailman/listinfo/zope-dev )
>>>