#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    ZA
    Posts
    2
    Rep Power
    0

    Yesterday's date


    Anybody know how too get yesterdays date ? Perhaps by manipulating the date command ?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Jersey
    Posts
    64
    Rep Power
    12
    Yep, date manipulation - the command:

    date -v-1d

    will give you the date output reading of one day previous on a FreeBSD system. Probably similar on other Unices, man date.

    -Gary
    Trying to change its program
    Trying to change the mode...crack the code
    Images conflicting into data overload
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    ZA
    Posts
    2
    Rep Power
    0
    Using Solaris.. could not get it too work. Anyone know ?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    12
    >Using Solaris.. could not get it too work. Anyone know ?
    % man date

    Read up on the commands that your date program supports. There should be an option for adjustment of varying degrees.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    137
    Rep Power
    0
    Don't know if the TZ (Timezone variable) is set in your environment. If so something like this will do the trick (I also don't have the -v option, or similar alternative, in date).
    Code:
    #!/usr/bin/ksh
    # Name       : pdate
    # Purpose    : Reports the date 'shift' hours from now, formatting is allowed
    
    typeset -i X
    
    if (( $# < 1 ))
    then
            print -u2 "Usage: $0 shift [ + format ]"
            print -u2 "Reports the date 'shift' hours from now. Format as in date."
            exit 0
    fi
    
    X=$1
    F=$2
    TZ=`echo $TZ | sed -e "s/MET-1/MET$((-1-X))/" -e "s/DST-2/DST$((-2-X))/"`
    
    if [[ -z $F ]]
    then
            date
    else
            date "$F"
    fi
    You might need to change $TZ to your $Timezone variable (if one excists that is).

IMN logo majestic logo threadwatch logo seochat tools logo