-### get last month from todays date in YYYY-MM format
-### OUT: last month as YYYY-MM
- # get today's date
- my (undef,undef,undef,undef,$Month,$Year,undef,undef,undef) = localtime(time);
- # $Month is already defined from 0 to 11, so no need to decrease it by 1
+### get last month/day from todays date in YYYY-MM format
+### IN : $Type : may be 'month' or 'day'
+### OUT: last month/day as YYYY-MM(-DD)
+ my ($Type) = @_;
+ my ($Day,$Month,$Year);
+ if ($Type eq 'day') {
+ # get yesterdays's date
+ (undef,undef,undef,$Day,$Month,$Year,undef,undef,undef) = localtime(time-86400);
+ # $Month is defined from 0 to 11, so add 1
+ $Month++;
+ } else {
+ # get today's date (month and year)
+ (undef,undef,undef,undef,$Month,$Year,undef,undef,undef) = localtime(time);
+ # $Month is already defined from 0 to 11, so no need to decrease it by 1
+ if ($Month < 1) {
+ $Month = 12;
+ $Year--;
+ };
+ }