Home > Net >  how many days have passed since Friday - Perl Variable
how many days have passed since Friday - Perl Variable

Time:07-21

I'm trying to calculate the number of days that have passed since last Friday?

For example, today is 7/19/2022, and last Friday was 7/15/2022 therefore, four days have passed. 7/19/2022 - 7/15/2022 = 4 days

I need this to update every day to just display # of days.

Can someone help me write this out to assign to a variable?

Thank you in advance!!! (new to coding)

CodePudding user response:

You can use localtime and simple modular arithmetic:

( (localtime)[6] - 5 ) % 7

( (current day index) - (friday day index) ) mod (days in a week)

CodePudding user response:

You can use Date::Calc Module. Here is the one liner version.

perl -E 'use Date::Calc qw(:all); say Delta_Days(2022,7,15, 2022,7,19,)'
  •  Tags:  
  • perl
  • Related