Template tag for "last month" ? *solved*

All about the standard Meteobridge devices based on mobile routers from TP-Link, D-Link, ASUS

Moderator: Mattk

Post Reply
svampen
Junior Boarder
Junior Boarder
Posts: 32
Joined: Fri Aug 16, 2019 10:57 am
Location: Sweden
Contact:

Template tag for "last month" ? *solved*

Post 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?
Last edited by svampen on Sat Jan 18, 2020 4:10 pm, edited 1 time in total.
PWS Villshärad/Halmstad, Sweden: vader.fishmoose.se DavisVPro + MB NanoSD.
svampen
Junior Boarder
Junior Boarder
Posts: 32
Joined: Fri Aug 16, 2019 10:57 am
Location: Sweden
Contact:

Re: Template tag for "last month" ?

Post 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>
...
PWS Villshärad/Halmstad, Sweden: vader.fishmoose.se DavisVPro + MB NanoSD.
User avatar
admin
Platinum Boarder
Platinum Boarder
Posts: 7874
Joined: Mon Oct 01, 2007 10:51 pm

Re: Template tag for "last month" ?

Post by admin »

Thanks for sharing. I don't know of a Meteobridge internal solution for that.
Post Reply