Problems, need help? Have a tip or advice? Post it here.
18 posts Page 1 of 2
Hi,

When I have an editable date fields on a couch page

Code: Select all
<cms:editable name='purchase_date' label='Purchase date' type='text'></cms:editable> 


and i like to show how long ago (in days) this date is. I think i have to get the Purchase date and subtract this from the current date..

Code: Select all
<cms:set days="<cms:date purchase_date format='Y-m-d H:i:s'/>" 'global'/>
<cms:set cur_date="<cms:date format='Y-m-d H:i:s'/>" 'global'/>


Can this be done with couch sub tag ?

EDIT: subtracting with dates doesn't seem to work, I could however do this with:

Code: Select all
<cms:php>
global $CTX;
$today = new DateTime(date($CTX->get('cur_date')));
$pday = new DateTime(date($CTX->get('purchase_date')));
$dayz = $pday->diff($today)->days;
$CTX->set( 'dayz', $dayz, 'global' );
</cms:php>

I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Hi Tomarnst,

We'll need to use PHP for the calculation.
So, is the PHP code you mentioned doing the trick?
Hi KK,

Yes, the PHP code is working.
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Great. Thanks for sharing the solution :)
hi KK,

It was more answering my own question. I tried to use the sub tag on this calculation... after a while I stopped my attempts and started to use PHP for this, since I had the solution earlier than a reply I edited the first post. :lol:
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
HI,

I did try this today, but nothing is showing!

I have the purchase_date in my index.php file so i did use the <cms:pages> and put your PHP code in between!

Is correct way to do it or did i do it wrong?

My code:
<cms:pages masterpage=k_user_template page_id=k_user_id >
<cms:php>
global $CTX;
$today = new DateTime(date($CTX->get('cur_date')));
$pday = new DateTime(date($CTX->get('purchase_date')));
$dayz = $pday->diff($today)->days;
$CTX->set( 'dayz', $dayz, 'global' );
</cms:php>
</cms:pages>
Hi,

is the k_user_template your index.php ?
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Yes index.php is where all info is stored. So beleve this then is k_template
hi kimheggen

k_user_template for me refers to the file profile.php in the users folder and not to the index.php

anyhow check in your index.php the <cms:template title=''> tag and use this title in your code

Code: Select all
<cms:pages masterpage='your template title' >
your stuff here
</cms:pages>


you can also use the <cms:dump /> to check the available variables on your page .
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Tomarnst wrote: hi kimheggen

k_user_template for me refers to the file profile.php in the users folder and not to the index.php

anyhow check in your index.php the <cms:template title=''> tag and use this title in your code

Code: Select all
<cms:pages masterpage='your template title' >
your stuff here
</cms:pages>


you can also use the <cms:dump /> to check the available variables on your page .


When doing this:

<cms:pages masterpage='your template title' >

I get error: ERROR: Tag "pages": masterpage 'Users' not found.

But when using the PHP tag should there be some SHOW tag to view the COUNT?
18 posts Page 1 of 2
cron