PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Sep 20, 2018 10:32 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Dates in Bash Script
PostPosted: Tue Mar 08, 2011 1:41 am 
Offline
Forum Commoner

Joined: Sat Nov 28, 2009 8:57 am
Posts: 55
I'm finding difficulty in getting the dates in my bash script .

Syntax: [ Download ] [ Hide ]
 date=`date +"%d"`  



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
Syntax: [ Download ] [ Hide ]
  date1=$[date*1]  
But now i'm not getting a value from it.....Can any one help me ?


Top
 Profile  
 
 Post subject: Re: Dates in Bash Script
PostPosted: Tue Mar 08, 2011 5:17 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria
Syntax: [ Download ] [ Hide ]
date=`date +%_-d`

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: Dates in Bash Script
PostPosted: Tue Mar 08, 2011 7:13 am 
Offline
Forum Commoner

Joined: Sat Nov 28, 2009 8:57 am
Posts: 55
Thanks :-)


Top
 Profile  
 
 Post subject: Re: Dates in Bash Script
PostPosted: Mon Feb 20, 2012 7:34 am 
Offline
Forum Newbie

Joined: Sat Feb 18, 2012 2:12 am
Posts: 10
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group