Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1013625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:07:54+00:00 2026-05-16T10:07:54+00:00

How do I tweak this to get yesterday’s date using localtime? use strict; sub

  • 0

How do I tweak this to get yesterday’s date using localtime?

use strict;

sub spGetCurrentDateTime;
print spGetCurrentDateTime;

sub spGetCurrentDateTime {
my ($sec, $min, $hour, $mday, $mon, $year) = localtime();
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my $currentDateTime = sprintf "%s %02d %4d", $abbr[$mon], $mday, $year+1900; #Returns => 'Aug 17 2010' 
return $currentDateTime;
}

~

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:07:55+00:00Added an answer on May 16, 2026 at 10:07 am

    The DST problem can be worked around by taking 3600s from midday today instead of the current time:

    #!/usr/bin/perl
    use strict;
    use warnings;
    use Time::Local;
    
    sub spGetYesterdaysDate;
    print spGetYesterdaysDate;
    
    sub spGetYesterdaysDate {
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime();
    my $yesterday_midday=timelocal(0,0,12,$mday,$mon,$year) - 24*60*60;
    ($sec, $min, $hour, $mday, $mon, $year) = localtime($yesterday_midday);
    my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
    my $YesterdaysDate = sprintf "%s %02d %4d", $abbr[$mon], $mday, $year+1900;
    return $YesterdaysDate;
    }
    

    In light of the “unspecified” documented behaviour of the strftime solution suggested by Chas, this approach might be better if you’re not able to test for expected-but-not-guaranteed results across multiple platforms.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read this and got really interested: Validating date format using regular expression so
I'm extremely new to JS and have this code that I'm trying to tweak.
Sorry, this might be a basic/stupid/noob question - I am just trying to tweak
I'm trying to tweak a behavior that I am seeing using Ruby on Rails
Can someone help me to tweak this regex?? I have this regex for twitter
This should be something encountered by programmers often, but I never tried to get
I couldn't seem to get my CSS working properly in IE (I'm using IE
learning html/css here. I can't seem to understand how to tweak this drop down
I have googled but I can't seem to get my script to work. this
How do you tweak the arguments that get passed in rspec's (v 2.6.1) post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.