Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use getdate on HP UX

Status
Not open for further replies.

starlite79

Technical User
Aug 15, 2008
89
US
I am wondering how to use getdate on HP UX. Based on the man page for getdate, I should just need to type getdate("yesterday"); to return yesterday's date. However, I get a syntax error when I do this.

The man page also mentions creating a user defined template of date formats, but if this is needed, how to I access it?

 
The getdate() function you are referring to is a C library function. Note that the man page is in section 3C, which is for C library functions. Are you writing and compiling C code here?

Annihilannic.
 
I noticed it was a C library. I am trying to call/invoke it in a script to get a date based on a string like "3 weeks ago" or something like that.
 
Well, you can't call it directly from a script, but you could use a little C programme such as:

Code:
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
        struct tm *thetime;
        time_t epoch;
        char tstr[32];

        epoch=time((long*)NULL);

        thetime=localtime(&epoch);
        thetime->tm_mday--;

        strftime(tstr,sizeof(tstr),"%d/%m/%y",thetime);

        printf("%s\n",tstr);

        exit(0);
}

Compile it using gcc -o yesterday yesterday.c.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top