in reply to Re^4: The day before a specific date
in thread The day before a specific date

Thank you for posting your code.

A good first step is to reduce the code to the minimum code needed for reproducing the problem. This helps us understand the code quicker, and likely it also helps you to understand the structure of your code better.

Can you please post the code without the HTML generation as a new reply, to your node? The generation of an output file is likely also not relevant to the problem.

Replies are listed 'Best First'.
Re^6: The day before a specific date
by jpys (Novice) on Jun 01, 2023 at 12:12 UTC
    Hello Corion, Earlier I received a piece of code in part like this:

    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11152433 use warnings; use Time::Piece; use Time::Seconds; { print "MONTH is first, then DAY. That is: MM/DD/YYYY\n"; @ARGV = '05/01/2023'; # MONTH comes first my $t = Time::Piece->strptime("$ARGV[0] 12", "%m/%d/%Y %H"); my $daybefore = ($t - ONE_DAY)->mdy("/"); printf <<END, $ARGV[0], $daybefore; Date as supplied: %s Date minus one day: %s END }
    download Outputs: MONTH is first, then DAY. That is: MM/DD/YYYY Date as supplied: 05/01/2023 Date minus one day: 04/30/2023

    As I attempted to comment before, this works perfectly but I don't have the luxury of manually entering the date as shown. (@ARGV = '05/01/2023';) My script provides the date in a string. From there I need the script to provide "the day before" in a different string. (At least that is the plan) When I attempt to use the string within the above code I cannot get it to work, I guess primarily because I don't understand Time::Piece well at all.

      So, how does your script provide the date?

      Do you have a subroutine previous_day() somewhere that you call?

      Please note that you have not reduced your original code, but started with some other code. Your problem seems to be how to integrate the code above with the code you have.

      The first step is to reduce (and understand) the code you have to something manageable. The second step then is to integrate the new code to get the previous day.

      While you have the parts to perform the second step, you haven't done the first step. The first step must be done before the second step.