in reply to Yesterday's date
Avoid all those problems with short or long days and daylight savings time switches by using the middle of the day :)
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11152433 use warnings; use Time::Piece; use Time::Seconds; @ARGV = '28/05/2023'; my $t = -ONE_DAY + Time::Piece->strptime("$ARGV[0] 12", "%d/%m/%Y %H") +; print localtime($t) . " should be near middle of the day\n\n"; printf "Date as supplied: %s\nDate minus one day: %s\n", $ARGV[0], $t- +>dmy("/");
Outputs:
Sat May 27 12:00:00 2023 should be near middle of the day Date as supplied: 28/05/2023 Date minus one day: 27/05/2023
|
|---|