#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    1
    Rep Power
    0

    Previous Date In LInux


    Hi Guys

    I am working on Solaris 9.0. How can I subtract system date by 1,2,3 days and stored into an variable

    Help Me pls


    Regards

    Amit Midha (Oracle DBA)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    USA
    Posts
    334
    Rep Power
    14
    Here is a pointer to an article on the subject:

    http://www.samag.com/documents/s=8284/sam0307b/0307b.htm
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Prague, Czech Rep.
    Posts
    117
    Rep Power
    15
    I had the same problem and I have solved it by simple C program delta_days:

    You can call it this way: delta_days -1 %D
    Format specification: see man page man strftime

    /************************************************************************/
    /* Program to generate datum that differs from current time */
    /* of a given number of days */
    /* Call: delta_d number_of_days format */
    /* format - see man strftime */
    /* delta_d < 0 : shift into the past */
    /* delta_d = 0 : current time and datum */
    /* delta_d > 0 : shift into the future */
    /************************************************************************/
    #include <stdio.h>
    #include <sys/types.h>
    #include <time.h>

    #define BUFL 1000

    int main (int argc, char *argv[])
    {
    time_t t; /* Time in seconds of era */
    unsigned long d; /* total number of days */
    char * endc; /* ending character of argv[1] */
    struct tm * loct; /* the time structure */
    char buf[BUFL]; /* working space */

    if (argc != 3) {
    fprintf (stderr, "%s: call: %s count_of_days format\n", argv[0], argv[0]);
    exit (1);
    }

    d = strtol (argv[1], &endc, (int)10);
    if (*endc != 0) {
    fprintf (stderr, "%s: count_of_days must be an integer\n", argv[0]);
    exit (1);
    }

    t = time (NULL) + d*24*60*60;
    loct = localtime (&t);
    strftime (buf, (size_t) BUFL, argv[2], loct);
    printf ("%s\n", buf);
    }

    Regards

IMN logo majestic logo threadwatch logo seochat tools logo