Well, if Perl is calculated as part of a script, then create a response to Perl. The next question is what determines the working day. Are you a store / shop that is open on Sunday? Saturday? Or 9-5 from Monday to Friday? What about the holidays?
Assuming you think Monday through Friday and the holidays are temporarily irrelevant, then you can use the Perl algorithm, which notes that wday will be 0 on Sunday after 6 on Saturday, and so if wday is 1, you need to subtract 3 * 86400 from time to time (); if wday is 0, you need to subtract 2 * 86400; and if wday is 6, you need to subtract 1 * 86400. This is what you have in the Korn shell - just do it in Perl:
#!/bin/perl -w use strict; use POSIX; use constant SECS_PER_DAY => 24 * 60 * 60; my(@days) = (2, 3, 1, 1, 1, 1, 1); my($now) = time; my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($now); print strftime("%Y-%m-%d\n", localtime($now - $days[$wday] * SECS_PER_DAY));
This assumes that you have a POSIX module; if not, you will need to do approximately the same printf () as you. I also use the ISO 8601 format for preference dates (also used by XSD and SQL) - hence the illustrated format.
Jonathan leffler
source share