in reply to Re^5: The day before a specific date
in thread The day before a specific date
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#!/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 }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: The day before a specific date
by Corion (Patriarch) on Jun 01, 2023 at 12:18 UTC |