Date format

Author Message

Francesc Febrer

Tuesday 02 March 2004 4:36:34 pm

Hi,

I created a class with a date field datatype called "data". When I whant print this on a template, I used this function:

{attribute_view_gui attribute=$:item.data_map.data}

but it shows 2004/03/03 (format y-m-d). I want do this but with the format d-m-y. I attempt using the {$:item.data_map.data.content.timestamp|datetime( 'custom', '%d.%m.%Y')} function, but always shows me 31.12.1969.

Please, how can I print the date using d-m-y?

Thanks.

James Packham

Wednesday 03 March 2004 1:24:19 am

Do attribute(show) and check that you're looking up a unix date (e.g. 107253223)

Regards,

James

Trond Åge Kvalø

Wednesday 03 March 2004 1:59:53 am

I have the same problem here, and I can't find any documentation on how to show the date I've stored as a date datatype in my class.

The only reference I've found is {$date|datetime(custom,"%m %y")} to use a custom formatting and I've found a page that describes the different formatting characters. But I don't know what the $date variable in this statement is.

Using Francesc's example, is it $node.object.data_map.data? or is it $node.object.data_map.data.content, and do we need to use attribute_view_gui attribute=$whatever_"$date"_is to display the date correctly or can we display it using for instance $node.object.data_map.data|datetime( 'custom', '%d.%m.%Y') ?

Lot's of questions there, but if someone knows, please tell me.

Best regards
Trond Kvalo

trondåge

James Packham

Wednesday 03 March 2004 2:18:19 am

|datetime( 'custom', '%d.%m.%Y') Converts a unix time date into something more meaningful - Unix dates count the number of seconds that have passed since 12:00am 1st Jan 1970, which doesn't really mean a lot to human eyes :) If you try to use this function to change any other date format into another date format it simply won't work - i.e. 03.23.2004 can not be changed into 23.03.2004 just by piping it with the function.

The good news is that all you need to do to make this work is to convert your date to unix time by working out the number of seconds in between 01.01.1970 and 03.23.2004, then piping it with datetime. It all sounds a bit complicated, but you can use it to your advantage because although the numbers are large the mathematics is very simple so you could, for example, make a count down to a certain date very easily.

Hope that helps,

Regards,

James

P.s. A way to simplify your problems might be to store your dates in unix time when you put them in the database.

Trond Åge Kvalø

Wednesday 03 March 2004 2:49:30 am

Hello James!

Thanks for the clarification. Always good to have you around :-)

Then next question then is of course, how do I make eZpublish store dates as unix format or convert the eZp format to unix format?
And how DO eZpublish store dates? There's a quarter of a bell ringing way back in my head that says something about integers..... but I don't know for sure.

Anyway, when eZ created the datatype date, they probably have thought about how to display it in a human readable format, I just hope someone could come forth and explain it to me ;-)

The task is rather simple, display a date stored in an object/node as a date datatype in a custom format. And if this involves taking whatever data format eZp uses and convert it to unix format and then pipe it into datetime, well... I guess a man's gotta do what a man's gotta do. But user friendly??? nah... ;-)

Best regards
Trond Kvalo

trondåge

James Packham

Wednesday 03 March 2004 3:38:47 am

>> Then next question then is of course, how do I make eZpublish store dates as
>> unix format or convert the eZp format to unix format?

I've got to come clean here, I'm not actually sure. I have a feeling that the code isn't provided with EZPublish because there's so many date formats out there that you might need to convert. You would probably have to write an extension yourself so you could pipe it in your input e.g. something like:

<input .... value={"23.12.2002"|MyDateExtension}>

>> And how DO eZpublish store dates? There's a quarter of a bell ringing way back
>> in my head that says something about integers

I'm not sure what you mean, but they're just put into the database as an attribute (look in the database table ezcontentobject at published). I think it's got more to do with Unix time being a (probably disputably) good generic format because of it's portability than issues with integers and floats.

>> Anyway, when eZ created the datatype date, they probably have thought about
>> how to display it in a human readable format

I think the big problem with ezp date/time is that you need to be happy to "get your hands dirty" if you want to do anything more customised. On the other hand it really isn't very difficult, just sit down with a pen and paper and figure out the maths needed to get the desired result.

Anyway I'm supposed to be working!

Good luck!

James

Alex Jones

Wednesday 03 March 2004 6:59:27 am

Here is the code I am currently using to display a date in a press release (the date field is named <i>released</i>):

{$:item.data_map.released.data_int|datetime(custom,"%F %j, %Y")}

Just sub <i>data</i> or whatever you have named your date field for <i>released</i> and it should work. It's important to remember that dates are not text fields (data_text), rather they are stored purely as integers (data_int) which I believe, is where the problem lies in your code.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Trond Åge Kvalø

Wednesday 03 March 2004 7:17:16 am

Hi Alex!

And thank you very much. Your code worked as a charm. And the clue here is not to rename my datefield to released, but to append the .data_int before piping it to the datetime function.

So, Francesc! You have to use the following code in your example:

{$:item.data_map.data.data_int|datetime( 'custom', '%d.%m.%Y')}

I really look forward to the day the eZ-guys manages do something with appendix C where all the datatypes are listed. Next step would be to show us how to use these datatypes in the template language. Oh well, I'm just happy someone gave me a solution.

best regards
Trond Kvalo

trondåge

Francesc Febrer

Wednesday 03 March 2004 4:36:56 pm

If I put

{$:item.data_map.data.data_int|datetime( 'custom', '%d.%m.%Y')}

then shows "31.12.1969".

Please, help me!!

Trond Åge Kvalø

Thursday 04 March 2004 12:08:33 am

Hmm, strange.

I see that you use attribute_view_gui to display the date.

Have you tried using just

$node.object.data_map.data.data_int|datetime(custom, '%d.%m.%Y')

Don't know if that will work but it's worth a shot

Best regards
Trond Kvalo

trondåge

Kjell Knudsen

Friday 16 July 2004 1:52:52 am

Just to say that this one saved me... when I finally was able to put in the correct search keywords.

So thanks Alex!

-kjell

Kjell Knudsen
http://www.icbl.org

Alex Jones

Tuesday 20 July 2004 8:34:01 am

Glad it helped you Kjell!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Kevin Myles

Thursday 22 July 2004 9:25:56 am

I was having a similiar issue.

I wanted the date to be shown in the article line, so i tookt he code from the article view and plugged it in, but it was showing it in a format i didn't want.

Playing with the code, i had some problems

             {$node.object.published|l10n(custom,"%F %d, %y")}
{$date|datetime(custom,"%F %d, %y")}
$node.object.data_map.data.data_int|datetime(custom, '%d.%m.%Y')
{$node.object.published|l10n(custom,"%F %d, %y")}
{$:item.data_map.published.data_int|datetime(custom,"%F %j, %Y")}
{$:item.data_map.date.data_int|datetime(custom,"%F %j, %Y")}
{$:item.data_map.published.data_int|datetime( 'custom', '%d.%m.%Y')}
{$node.object.data_map.data.data_int|datetime(custom, '%d.%m.%Y')}
{$node.object.published|datetime(custom, '%F %d, %Y')}
{$node.object.published|datetime( 'custom', '%d.%m.%Y')}

all of this code, in the article line template, would yield me:

1090416091
December 31, 69
$node.object.data_map.data.data_int|datetime(custom, '%d.%m.%Y')
1090416091
December 31, 1969
December 31, 1969
31.12.1969
31.12.1969
July 21, 2004
21.07.2004

Eventually, it worked out because i tried almost everything.
anyway, if you're having problems, fiddle with the code above and see what happens.

Mazen Shaheed

Thursday 02 June 2005 5:11:46 am

datetime( 'custom', '%d.%m.%Y') works with $node but not with {attribute_view_gui }.

Example:
{$node.object.data_map.date.content.timestamp|datetime( custom, '%d.%M.%Y')} works fine

BUT:
{attribute_view_gui attribute=$node.object.data_map.date.content.timestamp|datetime(custom, '%d.%M.%Y')} WON'T WORK

cheers

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.