[Zope] Date Manipulation
Martijn Pieters
mj@antraciet.nl
Wed, 03 Mar 1999 16:47:52 +0100
At 16:17 03/03/99 , Luke Duff wrote:
>Thanks for the help, but...
>
>My problem is a little bit harder than that. The data in field2 is date *and*
>time. So like this:
>
>field1 field2
>------ ---------------
>red 3/1/99 10:00 AM
>blue 3/1/99 11:00 AM
>green 3/1/99 03:00 PM
>brown 3/2/99 10:00 AM
>yellow 3/2/99 04:30 PM
>
>I've seen in the guide where you can format a data field when outputting, but
>how do actually extract the day-of-the-month number and put it in a temp
>variable. The pseudo-code I've used before to do this before is:
>
>tempday = 0
>for each record
> if tempday<>dayofmonth(datefield) then
> print out a header
> print out other fields
> tempday = dayofmonth(datefield)
>next
>
You'll have to use SQL function for this. In MySQL you could do the following:
SELECT field1, DATE_FORMAT(field2, "W, M d") as datefield FROM MyDB.
Put this in a Z SQL Method, and then the following DTML will get you your
results:
<!--#in MySQLMethod sort=datefield-->
<!--#if first-datefield-->
<!--#var datefield-->,
<BLOCKQUOTE>
<!--#/if-->
<!--#var field1-->
<!--#if last-datefield-->
</BLOCKQUOTE>
<!--#/if-->
<!--#else-->
Sorry, no colors in your query.
<!--#/in-->
--
M.J. Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-6254545 Fax: +31-35-6254555
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------