Community Documentation

Counter (x days before / past...)

Last updated May 3, 2005. Created by bertboerland on February 10, 2005.
Edited by puregin, bryan kennedy. Log in to edit this page.

A small block that displays the days after a certain date.

<?php
$day
= 30;
$month = 12;
$year = 1969;
$age= ((int)((mktime (0,0,0,$month,$day,$year) - time(void))/86400) * -1 );
print (
"My age in days is " . $age . ".");
?>

Comments

if we have nodes typeA with

if we have nodes typeA with date field 'field_date_a' and typeB with field 'field_additional_info' and we want to display in block on page typeB 'field_additional_info' only if time < (or >) 'field_date_a' how we can do it?

at 1st, from full and teaser views of typeB we disable 'field_additional_info'
2nd, create block with custom php code and setup to display him only on specific address /typeB/*
3rd and most hard to build snippet for this block
i don't know php, but i want to understand how it works
we need function to know value of 'field_date_a' (we assume, that we have only one page typeA and many pages typeB, so array from 'field_date_a' will have only one value)

please, help me to understand how it works

I'm looking to do something

I'm looking to do something kind of specific that I think may be close to this but I can't get it to work on my own. I'm starting a blog documenting the life of my child. I want to be able to put into the template for a blog node that the particular node was written on "Day X" of my child's life, so the fixed date would be the date of birth and instead of using today's date, the date the node was created.

Any thought on how to accomplish this?

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.