I'm trying to convert a string from 2000/12/31 ( which is the format a date string is returned by a sql query ) to 31-DEC-2000 which is the format I need to enter date values into the database. I figured I need to index into 'JANFEBMARAPR.... ' Now m_date is '2000/12/31', so I need to convert the 12 to an integer. but <dtml-call "REQUEST.set('month',_.string.atoi(m_date[5:7],10))"> gives me a null value for month. ------- Regards, Graham Chiu gchiu<at>compkarori.co.nz http://www.compkarori.com/dynamo - The Homebuilt Dynamo http://www.compkarori.com/dbase - The dBase bulletin
I don't have a direct answer to your question; but I thought I'd mention (in case you hadn't are ready seen them) the date-handling features built into DTML that make this kind of transformation easy. Check out Appendix A of http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.html -- Loren ----- Original Message ----- From: Graham Chiu <anon_emouse@hotmail.com> To: <zope@zope.org> Sent: March 04, 2000 06:57 PM Subject: [Zope] formatting a date string
I'm trying to convert a string from
2000/12/31 ( which is the format a date string is returned by a sql query )
to
31-DEC-2000
which is the format I need to enter date values into the database.
I figured I need to index into 'JANFEBMARAPR.... '
Now m_date is '2000/12/31', so I need to convert the 12 to an integer.
but <dtml-call "REQUEST.set('month',_.string.atoi(m_date[5:7],10))">
gives me a null value for month.
------- Regards, Graham Chiu gchiu<at>compkarori.co.nz http://www.compkarori.com/dynamo - The Homebuilt Dynamo http://www.compkarori.com/dbase - The dBase bulletin
_______________________________________________ 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 )
In article <007301bf864d$e4f92440$2101a8c0@pavilion>, Loren Stafford <lstaffor@dynalogic.com> writes
I don't have a direct answer to your question; but I thought I'd mention (in case you hadn't are ready seen them) the date-handling features built into DTML that make this kind of transformation easy. Check out Appendix A of http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.html
-- Loren
Thanks, however I think they only work on date objects. There is a DateTime() function to create date objects mentioned in the DTML guide, but it doesn't seem to be documented. Nevertheless, I would be interested in why atoi does not work for me. ------- Regards, Graham Chiu gchiu<at>compkarori.co.nz http://www.compkarori.com/dynamo - The Homebuilt Dynamo http://www.compkarori.com/dbase - The dBase bulletin
In article <PuuGwbAe0dw4EwKK@compkarori.com>, Graham Chiu <anon_emouse@hotmail.com> writes
There is a DateTime() function to create date objects mentioned in the DTML guide, but it doesn't seem to be documented.
Okay, it's simple enough - <dtml-call "REQUEST.set('mydate',_.DateTime('2000/12/31'))"> creates the date object I need to then reformat it. ------- Regards, Graham Chiu gchiu<at>compkarori.co.nz http://www.compkarori.com/dynamo - The Homebuilt Dynamo http://www.compkarori.com/dbase - The dBase bulletin
In article <4tU7QdA2Cew4Ew9x@compkarori.com>, Graham Chiu <anon_emouse@hotmail.com> writes
In article <PuuGwbAe0dw4EwKK@compkarori.com>, Graham Chiu <anon_emouse@hotmail.com> writes
There is a DateTime() function to create date objects mentioned in the DTML guide, but it doesn't seem to be documented.
Okay, it's simple enough -
<dtml-call "REQUEST.set('mydate',_.DateTime('2000/12/31'))">
creates the date object I need to then reformat it.
Oops, spoke too soon. Spent the last few hours trying to suss this out without any progress :-( I have a variable called START returned by a sqlquery <dtml-call "REQUEST.set('startdate',START)"> start is <dtml-var startdate> and that's okay <dtml-call "REQUEST.set('month',_.DateTime(startdate).aMonth"> That, and variations of the same, dies with Error Type: TypeError Error Value: __div__ nor __rdiv__ defined for these operands Why is that these simple little things are so difficult in Zope? ------- Regards, Graham Chiu gchiu<at>compkarori.co.nz http://www.compkarori.com/dynamo - The Homebuilt Dynamo http://www.compkarori.com/dbase - The dBase bulletin
On Sun, 5 Mar 2000, Graham Chiu wrote:
Okay, it's simple enough -
<dtml-call "REQUEST.set('mydate',_.DateTime('2000/12/31'))">
creates the date object I need to then reformat it.
Oops, spoke too soon. Spent the last few hours trying to suss this out without any progress :-(
I have a variable called START returned by a sqlquery
<dtml-call "REQUEST.set('startdate',START)"> start is <dtml-var startdate>
Is START being returned as a string, or as a DateTime from your query? If it's being returned as a string, you need: <dtml-call "REQUEST.set('startdate', _.DateTime(START))">
and that's okay
<dtml-call "REQUEST.set('month',_.DateTime(startdate).aMonth">
That, and variations of the same, dies with
Error Type: TypeError Error Value: __div__ nor __rdiv__ defined for these operands
aMonth() is a method, not an attribute. You need to _call_ it, i.e.: <dtml-call "REQUEST.set('month', _.DateTime(startdate).aMonth())"> or, if startdate is already a DateTime: <dtml-call "REQUEST.set('month', startdate.aMonth())"> Another way of doing this, however, is something like the following: <dtml-call "REQUEST.set('mydate', _.DateTime('2000/12/31'))"> <dtml-var mydate fmt=dd>-<dtml-var mydate fmt=aMonth>-<dtml-var mydate fmt=year> Voila.
Why is that these simple little things are so difficult in Zope?
The above does not seem too difficult to me. You made a few simple mistakes, that's all. --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
On Sun, 5 Mar 2000, Jeff Hoffman wrote:
Another way of doing this, however, is something like the following:
<dtml-call "REQUEST.set('mydate', _.DateTime('2000/12/31'))"> <dtml-var mydate fmt=dd>-<dtml-var mydate fmt=aMonth>-<dtml-var mydate fmt=year>
I forgot that you can also use C-style formatting, which reads much better in this case: <dtml-var mydate fmt="%d-%b-%Y"> See: http://www.zope.org/Members/AlexR/CustomDateFormats --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
In article <Pine.SOL.4.10.10003051220140.12597-100000@argyle>, Jeff Hoffman <jeff.hoffman@goingv.com> writes
I have a variable called START returned by a sqlquery
<dtml-call "REQUEST.set('startdate',START)"> start is <dtml-var startdate>
Is START being returned as a string, or as a DateTime from your query? If it's being returned as a string, you need:
<dtml-call "REQUEST.set('startdate', _.DateTime(START))">
and that's okay
It all seemed to work when I tried this <dtml-call "REQUEST.set('startdate',_.str(START))">
<dtml-call "REQUEST.set('month',_.DateTime(startdate).aMonth">
That, and variations of the same, dies with
Error Type: TypeError Error Value: __div__ nor __rdiv__ defined for these operands
aMonth() is a method, not an attribute. You need to _call_ it, i.e.:
<dtml-call "REQUEST.set('month', _.DateTime(startdate).aMonth())">
It works as written <dtml-call "REQUEST.set('month',_.DateTime(startdate).aMonth"> thanks for the response. ------- Regards, Graham Chiu gchiu<at>compkarori.co.nz http://www.compkarori.com/dynamo - The Homebuilt Dynamo http://www.compkarori.com/dbase - The dBase bulletin
I'm still having difficulty with this. I want to add a date to a character string ( dated user comments ) to store into a sqltable. <dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date)"> The docs say that this returns a date string ( as opposed to a date object? ) <dtml-call "REQUEST.set('mystring', 'date: '+CurrentDate)"> produces this error Error Type: TypeError Error Value: illegal argument type for built-in operation And if I try this <dtml-call "REQUEST.set('mystring', 'date: '+_.str(CurrentDate))"> mystring is then 'date:' ------- Regards, Graham Chiu gchiu<at>compkarori.co.nz http://www.compkarori.co.nz/x.php?/Shopping http://www.compkarori.com/dynamo - The Homebuilt Dynamo http://www.compkarori.com/dbase - The dBase bulletin
Graham Chiu schrieb:
I'm still having difficulty with this.
I want to add a date to a character string ( dated user comments ) to store into a sqltable.
<dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date)">
try: <dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date())"> and it should work. hth, Thomas
On Tue, 7 Mar 2000, Graham Chiu wrote:
I'm still having difficulty with this.
I want to add a date to a character string ( dated user comments ) to store into a sqltable.
<dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date)">
This is the same problem as last time. You must CALL the Date method, not just reference it. The above line should read: <dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date()"> Note the use of parens on Date(). Try it for yourself by putting the following in a DTML Method: <dtml-var expr="ZopeTime().Date"> You get: <method DateTime.Date of DateTime instance at 568eb0> if you do a View | Source in your browser.
The docs say that this returns a date string ( as opposed to a date object? )
It does, if you CALL it.
<dtml-call "REQUEST.set('mystring', 'date: '+CurrentDate)">
produces this error
Error Type: TypeError Error Value: illegal argument type for built-in operation
Here is some code that works: <dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date())"> <dtml-call "REQUEST.set('mystring', 'date: ' + CurrentDate)"> <dtml-var mystring>
And if I try this
<dtml-call "REQUEST.set('mystring', 'date: '+_.str(CurrentDate))">
Again, you've never set CurrentDate correctly. View the source of the page that comes back and you will see the problem.
mystring is then 'date:'
Hope this helps. --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
In article <Pine.SOL.4.10.10003070936520.22456-100000@argyle>, Jeff Hoffman <jeff.hoffman@goingv.com> writes
Here is some code that works:
<dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date())"> <dtml-call "REQUEST.set('mystring', 'date: ' + CurrentDate)"> <dtml-var mystring>
Thanks. What had me confused is that <dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date())"> <dtml-var Currentdate> and <dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date)"> <dtml-var Currentdate> both display the same date string whereas I guess the latter should display an error. It only reports an error when I try to do something else with the variable. ------- Regards, Graham Chiu gchiu<at>compkarori.co.nz http://www.compkarori.com/dynamo - The Homebuilt Dynamo http://www.compkarori.com/dbase - The dBase bulletin
On Wed, 8 Mar 2000, Graham Chiu wrote:
What had me confused is that
<dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date())"> <dtml-var Currentdate>
and
<dtml-call "REQUEST.set('CurrentDate', ZopeTime().Date)"> <dtml-var Currentdate>
both display the same date string whereas I guess the latter should display an error. It only reports an error when I try to do something else with the variable.
In the second case, I guess <dtml-var CurrentDate> is recognizing that CurrentDate is a reference to a function and calling it. I understand, now, how that had you confused. Anyway, glad it's working! --Jeff --- Jeff K. Hoffman 704.849.0731 x108 Chief Technology Officer mailto:jeff@goingv.com Going Virtual, L.L.C. http://www.goingv.com/
participants (5)
-
Graham Chiu -
Jeff Hoffman -
Jeff K. Hoffman -
Loren Stafford -
Thomas Weiner