Since your "yesterday" question explicitly said DD/MM/YYYY and this question explicitly says MMDDYYYY (by which I think you mean MM/DD/YYYY), I will provide both answers. Pick the one you really want.

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

Outputs:

DAY is first, then MONTH. That is: DD/MM/YYYY Date as supplied: 01/05/2023 Date minus one day: 30/04/2023 MONTH is first, then DAY. That is: MM/DD/YYYY Date as supplied: 05/01/2023 Date minus one day: 04/30/2023

In reply to Re: The day before a specific date by tybalt89
in thread The day before a specific date by jpys

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.