Get yesterday s date in bash on Linux DST-safe

0 votes

I have a shell script that runs on Linux and uses this call to get yesterday's date in YYYY-MM-DD format:

date -d "1 day ago" '+%Y-%m-%d'

It works most of the time, but when the script ran yesterday morning at 2013-03-11 0:35 CDT it returned "2013-03-09" instead of "2013-03-10".

Presumably daylight saving time (which started yesterday) is to blame. I'm guessing the way "1 day ago" is implemented it subtracted 24 hours, and 24 hours before 2013-03-11 0:35 CDT was 2013-03-09 23:35 CST, which led to the result of "2013-03-09".

So what's a good DST-safe way to get yesterday's date in bash on Linux?

Dec 14, 2022 in Linux Administration by erzan
• 630 points
1,322 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Linux Administration

–1 vote
1 answer

How to get octal file permission in linux?

You can use this: stat -c "%a %n" ...READ MORE

answered Jan 3, 2019 in Linux Administration by Omkar
• 69,220 points
2,622 views
0 votes
1 answer

How to create directory of current username in ruby on Linux server

Hi, The command whoami is used to know ...READ MORE

answered Nov 25, 2020 in Linux Administration by MD
• 95,460 points
803 views
0 votes
0 answers

Linux command to display date in unix format

What command can I use in Linux ...READ MORE

Apr 13, 2022 in Linux Administration by Aditya
• 7,680 points
541 views
0 votes
0 answers

Get Selenium to work with Brave browser on Linux

I am trying to get Selenium to ...READ MORE

Apr 14, 2022 in Linux Administration by Soham
• 9,710 points
1,584 views
0 votes
0 answers

On Linux, does the remove command "rm" run in the background?

I am trying to run my test ...READ MORE

Apr 20, 2022 in Linux Administration by Edureka
• 13,690 points
661 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,240 points
1,208 views
+1 vote
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP