Professional Web Applications Themes

date from yesterday - SCO

Hi all! Does anyone know, how to get a date-string from yesterday within a shellscript? The output should look like: $ date +%y%m%d Thanks in advance! Erich...

  1. #1

    Default date from yesterday

    Hi all!

    Does anyone know, how to get a date-string from yesterday within a
    shellscript?

    The output should look like:
    $ date +%y%m%d

    Thanks in advance!
    Erich
    Erich Guest

  2. #2

    Default Re: date from yesterday

    You could do something like:

    #!/bin/ksh
    let YSTD=`date +%d`-1
    YandM=`date +%y%m`
    print ${YandM}${YSTD}

    regards,

    Albert van Alphen

    Erich Aigner wrote: 

    Albert Guest

  3. #3

    Default Re: date from yesterday

    In article <3f6841c8$0$282$nl.uu.net>, Albert van Alphen <steinweg-nospam.com> wrote: 

    And if today happens to be the 1st of the month...?

    OP: See http://aplawrence.com/Unix/yesterday.html


    Ian.
    Ian Guest

  4. #4

    Default Re: date from yesterday

    For the sake of good order, this script is far from perfect.
    This script doesn't keep in mind when the today is the first day of the
    month, in which case yesterday is the last day of the month before.
    So if today is 1 septhember 2003, than yesterday has to be, ofcourse,
    31st august 2003.
    In which case you have to keep track of how many days there are in a
    particular month.
    You even should keep track of the year, in case today is the date is 1st
    January.
    But a more accurate alternative script could be someting like:

    QUOTE

    #!/bin/ksh

    let LAST_MONTH=$(date +%m)-1

    case $LAST_MONTH in
    1|3|5|7|8|10|12) let DAYS=31 ;;
    4|6|9|11) let DAYS=30 ;;
    2) let DAYS=28 ;;
    esac

    if (( $(date +%d) == 1 ))
    then
    MONTH=$LAST_MONTH
    let YSTD=$DAYS
    else
    MONTH=$(date +%m)
    let YSTD=`date +%d`-1
    fi

    YEAR=$(date +%y)
    print ${YEAR}${MONTH}${YSTD}

    UNQUOTE

    This scrkipt is not tested, could have a bug.

    regards,

    Albert van Alphen


    Albert van Alphen wrote: 
    >
    >[/ref]

    Albert Guest

  5. Moderated Post

    Default Re: date from yesterday

    Removed by Administrator
    Erich Guest
    Moderated Post

  6. Moderated Post

    Default Re: date from yesterday

    Removed by Administrator
    Ian Guest
    Moderated Post

  7. Moderated Post

    Default Re: date from yesterday

    Removed by Administrator
    Erich Guest
    Moderated Post

  8. #8

    Default Re: date from yesterday

    In article <3f684b43$0$280$nl.uu.net>,
    Albert van Alphen <steinweg-nospam.com> wrote: 
     
     
     
     

    Or if somone is ambitious they can take one of the OpenSource
    versions of date that uses the -v flag.

    Then you can use any of the y,m,w,d,h,m with a +N or -N where N is
    an integer and used in the form of -v-3d for 3 days in the past to
    adjust units, but without the -/+ preceding the unit it gives the
    numeric unit equivalent, so you can specify any date in the Unix
    range. It will work from approximately 1902 thru February 18th 2038.

    From the example:
    date -v1d -v3m -v0y -v-1d
    Sets the day to the first, the month to March, the year to 2000,
    and then moves back 1 day.

    Make EOM calculations easy.

    This is from the BSD sources and may take a bit of diddling for the
    SysV arena but it surely makes things handy.


    --
    Bill Vermillion - bv wjv . com
    Bill Guest

  9. #9

    Default Re: date from yesterday

    Bill Vermillion typed (on Wed, Sep 17, 2003 at 03:57:01PM +0000):
    | Or if somone is ambitious they can take one of the OpenSource
    | versions of date that uses the -v flag.
    |
    | Then you can use any of the y,m,w,d,h,m with a +N or -N where N is
    | an integer and used in the form of -v-3d for 3 days in the past to
    | adjust units, but without the -/+ preceding the unit it gives the
    | numeric unit equivalent, so you can specify any date in the Unix
    | range. It will work from approximately 1902 thru February 18th 2038.
    |
    | >From the example:
    | date -v1d -v3m -v0y -v-1d
    | Sets the day to the first, the month to March, the year to 2000,
    | and then moves back 1 day.
    |
    | Make EOM calculations easy.
    |
    | This is from the BSD sources and may take a bit of diddling for the
    | SysV arena but it surely makes things handy.

    Simpler solution: use Bob Stockler's awk scripts.

    ftp.jpr.com:/pub/datemath.tgz

    --
    JP
    Jean-Pierre Guest

  10. #10

    Default Re: date from yesterday

    Erich Aigner <at> wrote in message news:<3f682427$0$31724$highway.telekom.at>... 

    install sh-utils from skunkware, which includes gnu date

    rftp -g -bh pcunix.com /pub/bkw setup_gnu
    chmod 755 setup_gnu
    ./setup_gnu sh-utils-2.0

    then:

    gdate -d "-1 day" +%y%m%d


    Brian K. White -- com -- http://www.aljex.com/bkw/
    +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
    filePro BBx Linux SCO Prosper/FACTS AutoCAD #callahans Satriani
    Brian Guest

  11. #11

    Default Re: date from yesterday

    On Wed, Sep 17, 2003 at 12:11:50PM -0400, Jean-Pierre Radley wrote:
    | Bill Vermillion typed (on Wed, Sep 17, 2003 at 03:57:01PM +0000):
    | | Or if somone is ambitious they can take one of the OpenSource
    | | versions of date that uses the -v flag.
    | |
    | | Then you can use any of the y,m,w,d,h,m with a +N or -N where N is
    | | an integer and used in the form of -v-3d for 3 days in the past to
    | | adjust units, but without the -/+ preceding the unit it gives the
    | | numeric unit equivalent, so you can specify any date in the Unix
    | | range. It will work from approximately 1902 thru February 18th 2038.
    | |
    | | >From the example:
    | | date -v1d -v3m -v0y -v-1d
    | | Sets the day to the first, the month to March, the year to 2000,
    | | and then moves back 1 day.
    | |
    | | Make EOM calculations easy.
    | |
    | | This is from the BSD sources and may take a bit of diddling for the
    | | SysV arena but it surely makes things handy.
    |
    | Simpler solution: use Bob Stockler's awk scripts.
    |
    | ftp.jpr.com:/pub/datemath.tgz

    And it works for all years from 0001 through 9999.

    Users in countries that didn't switch from the Julian
    to the Gregorian calendar when the USA did will have
    to edit it to account for days lost when the switch
    was made. As written, the program skips the days
    between 09/02/1752 and 09/14/1752.

    --
    Bob Stockler - iglou.com
    Author: MENU EDIT II - The BEST Creator/Editor/Manager for filePro User Menus.
    Fully functional (time-limited) demos available by email request (specify OS).
    Bob Guest

Similar Threads

  1. How to get the date of "Yesterday"
    By lxmanxl in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: October 19th, 01:49 AM
  2. Why Cox went down day before yesterday?
    By jef@eyeintegrated.com in forum PHP Development
    Replies: 0
    Last Post: August 14th, 03:05 PM
  3. Easy way to get yesterday's date
    By Jeffrey Ross in forum AIX
    Replies: 5
    Last Post: July 28th, 11:45 AM
  4. get yesterday's date
    By Joel Gacosta in forum Microsoft SQL / MS SQL Server
    Replies: 5
    Last Post: July 1st, 11:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139