1832983 Members
3017 Online
110048 Solutions
New Discussion

How to manipulate date?

 
Rashid Ali
Frequent Advisor

How to manipulate date?

I want to know what day/weekday was yesterday or ten days ago, anybody knows how can I get the result?

Thanks in advance
7 REPLIES 7
David Peacock
Frequent Advisor

Re: How to manipulate date?

The "cal" command will print the calender:

# cal
March 2001
S M Tu W Th F S
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

"cal 2001" wil print all of the months and days in the year 2001


veni, vidi, vmstat
David Peacock
Frequent Advisor

Re: How to manipulate date?

The format is messed up on that last reply.
I will try again:

# cal
March 2001
S M Tu W Th F S
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


veni, vidi, vmstat
Rashid Ali
Frequent Advisor

Re: How to manipulate date?

I want to get this result in my shell script. For example, my script requires what day/weekday it was ten days ago or what day/weekday it is ten days later from now.
Patrick Wallek
Honored Contributor

Re: How to manipulate date?

There is a set of gnu shell utilities that contains a date command that will do what you want. I use it and it works pretty well.

You can get it from here:

http://hpux.connect.org.uk/hppd/hpux/Gnu/sh_utils-2.0/
Andreas Voss
Honored Contributor

Re: How to manipulate date?

Hi,

here a simple c progamm to get the past date:
#include
#include

main(argc, argv)
int argc;
char **argv;
{
time_t seconds;
struct tm *timeptr;

if(argc > 1)
{
seconds = time((long *)0) - atoi(argv[1])*24*60*60;
timeptr = localtime(&seconds);
fputs(asctime(timeptr), stdout);
exit(0);
}
else
exit(1);
}

Just compile it:
cc predate.c -o/usr/contrib/bin/predate

and call it with ie:

predate 10

This prints the date before 10 days.

Regards
Rajeev Tyagi
Valued Contributor

Re: How to manipulate date?

Hi attaching a script this will manipulate the date as per your need.

Regards
James L Shirley (4075)
Occasional Advisor

Re: How to manipulate date?

 
No Indian prince has to his palace ...