It might not be any faster, but you can also do it as follows:
use POSIX qw( strftime ); use Time::Local qw( timegm_nocheck ); my ($day, $mon, $year, $wday) = (localtime())[3..6]; # Defaults to now. $year += 1900; $day += (7 - $wday + 4) % 7; $next_th = timegm_nocheck(0,0,0,$day,$mon,$year); print(strftime('%Y-%m-%d', gmtime($next_th)), "\n");
Only core modules are used.
Update: Now using GMT functions for the date to avoid problems from daylight savings time. (This should speed things up a bit too!) The date is still in localtime since we used localtime to fetch the current date.
Update: I had two names for the same variable ($day and $mday). Fixed.
In reply to Re: code to get the date for "next Thursday"
by ikegami
in thread code to get the date for "next Thursday"
by bfdi533
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |