How bash treats literal date value and retrieve year, month and date?

Hi,

I am trying to add few (say 3 days) to sysdate using -

date -d '+ 3 days' +%y%m%d 

and it works as expected.

But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value is in this format.

I mean, 12/11/04 I know 12 is yy, 11 is dd and 04 is mm but BASH may think 12 as yy, 11 as mm and 04 as dd.

Regards,
Pointers

Hi.

Depending on your OS, shell, etc. (which you forgot to post), and level of expertise, one or more of hte following may be of interest. I often use dateutils ... cheers, drl

Date, time arithmetic, math

        1) gnu date

        2) ksh ( version 93, not 88; ksh93 M 93t+ ) printf, e.g:
           printf "%(%Y-%m-%d)T\n" "yesterday"

        3) date.pl (limited arithmetic, but "date.pl -d '- 1 day'" works)
           ( http://www.unix.com/tips-tutorials/
           239167-general-purpose-date-script.html)

        4) dconv et al, e.g. ddiff, dconv, strptime (parsing), etc.
           ( dateutils: http://www.fresse.org/dateutils/ )

        5) tm2tm (, OK in 32-bit; fails to compile in 64-bit)
           ( http://www.unix.com/shell-programming-scripting/
           146216-date-difference-between-freebsd-linux.html#post302463136 )

        6) perl custom formatting (with function POSIX::strftime, "perldoc POSIX")

        7) date-cpan.pl, cpan perl date
           ( http://cpansearch.perl.org/src/CWEST/ppt-0.14/src/date/date.jgross )

        8) For small changes, say, "yesterday" in bash, ksh
           TZ=CST+24 date +%Y%m%d
           csh, tcsh
           setenv TZ CST+24 ; date +%Y%m%d

        9) Check for legal date:
           manstat:validata ( http://oldwww.acm.org/perlman/stat/ )

        10) Check for legal date:
            validate (local perl code)

        11) Shell, ksh, date calculations:
            www.unix.com/unix-for-dummies-questions-and-answers/4870-days-elapsed-between-2-dates.html

This isn't being done by BASH, everything here is being done by date - GNU date specifically. Basic POSIX date doesn't have "+ 3 days" (but in my opinion, should.)

GNU date - and most of the civilized world sincd 1988 - understand dates in the ISO standard YYYY/MM/DD form. This method has pretty clear advantages like dates being trivially sortable. So you could do -d "2016/12/31 + 3 days", etc.