Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid date options in Ubuntu

Tags:

bash

ubuntu

I have a shell script where I ask the system to return the year, 660days ago. On my Mac, I use this:

date -j -v-660d +"%Y"

If run today, that would return 2011.

I'm moving the script to an Ubuntu machine, and I receive an error, stating that the -j and -v options are invalid.

I've looked at the man page, looking for equivalent options, but haven't been able to find a solution.

Any help is appreciated.

like image 483
majordomo Avatar asked Apr 18 '13 18:04

majordomo


People also ask

What does invalid date format mean?

Check the content of the spreadsheet you are trying to upload. Dates in your spreadsheet may be formatted in ways other than mmm-yyyy, such as dd-mmm-yyyy. Right-click these dates and click Format.

How do I print Yyyymmdd format in Unix?

To format date in YYYY-MM-DD format, use the command date +%F or printf "%(%F)T\n" $EPOCHSECONDS . The %F option is an alias for %Y-%m-%d . This format is the ISO 8601 format.

What is date in shell script?

Task: Display date in mm-dd-yy format Open a terminal and type the following date command: $ date +"%m-%d-%y" Sample outputs: 02-27-07.

What is the date command in bash?

Bash Date Format MM-DD-YYYY To format date in MM-DD-YYYY format, use the command date +%m-%d-%Y . Please observe the upper and lower case letters : %m for month, %d for day and %Y for year. %M would mean minutes.


1 Answers

This should work:

$ date -d '660 days ago' +%Y
2011
like image 140
Lev Levitsky Avatar answered Oct 02 '22 15:10

Lev Levitsky