Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.
Moderator: General Moderators
-
nithinkk
- Forum Commoner
- Posts: 55
- Joined: Sat Nov 28, 2009 7:57 am
Post
by nithinkk »
I'm finding difficulty in getting the dates in my bash script .
The above code will output 08....but i want only 8 not zero !!! how to do it ?
Till yesterday i was getting it by doing
But now i'm not getting a value from it.....Can any one help me ?
-
VladSun
- DevNet Master
- Posts: 4313
- Joined: Wed Jun 27, 2007 9:44 am
- Location: Sofia, Bulgaria
Post
by VladSun »
There are 10 types of people in this world, those who understand binary and those who don't
-
nithinkk
- Forum Commoner
- Posts: 55
- Joined: Sat Nov 28, 2009 7:57 am
Post
by nithinkk »
Thanks

-
qeemat
- Forum Newbie
- Posts: 10
- Joined: Sat Feb 18, 2012 1:12 am
Post
by qeemat »
The new short way:
$ date -d '1 day ago' +'%Y/%m/%d'
2009/07/21
Or the longer way:
Yesterday in epoch seconds
$ yesterday=$((`date +'%s'` - 86400))
Get default formatted yesterday's date
$ date -d "1970-01-01 $yesterday sec"
Tue Feb 17 01:27:32 PST 2009
Same thing in YY-MM-DD
$ date -d "1970-01-01 $yesterday sec" +"%Y-%m-%d"
2009-02-17