Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to execute date command in unix server for yesterday. The commands tried are :

date --date ="1 day ago"
date --date ="1 days ago"  
date --date ="yesterday
date --date ="-1 day"

These command work in a server but the same command does not work in few other servers, where date prints properly the current date. Could anyone suggest what could be the issue with the other servers?

The server details: SunOS wupsa02a0014 5.10 Generic_147440-15 sun4u sparc SUNW,SPARC-Enterprise

share|improve this question
    
Stephane has already provided the answer, but I wanted to point out that you should look to the man pages for issues like this. Then you'd know you were trying to use options that are not available in a (POSIX) standard date command. Solaris' man pages are detailed and complete. –  Tim B Mar 27 '13 at 12:30

1 Answer 1

up vote 1 down vote accepted

Either remove the = or the space after --date and change those Unicode quotes (U201D) to the ASCII quote character (U0022). So:

date --date="1 day ago"

or

date --date yesterday

or

date -d yesterday

Note that -d/--date is not a standard Unix date option and is only available with GNU date. So if that Unix server is not a Linux distribution or other GNU based system, you'll have to install GNU date there or use alternative options for date calculation.

share|improve this answer
    
I get an error in all the above cases like: date: illegal option -- d, date: illegal option -- date=1 day ago etc –  Swagatika Mar 27 '13 at 7:03
3  
@Swagatika. Yes, your date is not the GNU date. –  Stéphane Chazelas Mar 27 '13 at 7:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.