Page 1 of 1

Template tag for "last month" ? *solved*

Posted: Wed Jan 08, 2020 4:49 pm
by svampen
Hi
I am trying to code a small page with some statistics.

I want to show the total rainfall for "the current month" and "the last month". I.e. now it is January, so I want to show rainfall for January side-by-side with December.

How to get the number is no problem, but is it possible to get the name of the previous month through a template-tag?

[MMM] results in "Jan", so that is ok. But how to get the previous month? :?:
(I managed to get "last year" by making a small substraction like this: {*[YYYY]-1*0} but that is just a number. Month in text is not.)

Any ideas?

Re: Template tag for "last month" ?

Posted: Thu Jan 09, 2020 3:36 pm
by svampen
I solved it.
The right way or not, I don't know.

I don't like unfinished threads, so here is how I made it with a php-script:

Code: Select all

...
<span class="greenvalue">[rain0total-monthsum:--] mm&nbsp;&nbsp;[MMM]</span><br>
<span class="greenvalue">[rain0total-sum@M1:--] mm&nbsp;
<?php
	$m = [M]; 
	switch($m) {
	case 1: echo "Dec"; break;
	case 2: echo "Jan"; break;
	case 3: echo "Feb"; break;
	case 4: echo "Mar"; break;
	case 5: echo "Apr"; break;
	case 6: echo "May"; break;
	case 7: echo "Jun"; break;
	case 8: echo "Jul"; break;
	case 9: echo "Aug"; break;
	case 10: echo "Sep"; break;
	case 11: echo "Oct"; break;				
	case 12: echo "Nov"; break;
	default: echo "--"; break;
	}
?>
</span>
...

Re: Template tag for "last month" ?

Posted: Sat Jan 11, 2020 1:54 pm
by admin
Thanks for sharing. I don't know of a Meteobridge internal solution for that.