good afternoon,
can someone help me, I need to make a script where n subtract days to a date.
I am using AIX 5.3.
Greetings.
good afternoon,
can someone help me, I need to make a script where n subtract days to a date.
I am using AIX 5.3.
Greetings.
Use perl:-
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
my $today = time;
my $n_day = $today - 48 * 60 * 60;
my $formatted = strftime "%m/%d/%Y", ( localtime($n_day) );
print "n_day = $formatted\n";
I am using shell script.
#!/bin/sh
Greetings
You can use the "TZ" variable and modify it. Note the difference in the output of these commands (try them out):
(TZ="GMT" ; date)
(TZ="GMT-24" ; date)
(TZ="GMT+24" ; date)
"date" calculates the date/time from the systems clock (which runs in UTC - Universal Time Coordinated) by applying the timezone as a modificator. Therefore, by modifying the timezone information, you can do date arithmetics. Because "TZ" is a variable like any other (it is set in "/etc/environment") you can simply modify it in a subshell without any consequences outside (therefore "(...)" ).
I hope this helps.
bakunin
Brilliant. But I did notice that you need to compensate for hours west of GMT,
offset must be an integer number of hours, and the expression may only have one operator (ie. "EST+5+$OFFSET" is invalid)
#!/bin/sh
# $1 is number of hours to shift date
if [ $# -ne 1 ]
then
date
exit
fi
# EST is 5 hours west of GMT
OFFSET=`expr $1 + 5`
if [ $OFFSET -lt 0 ]
then
OFFSET=$OFFSET
else
OFFSET=+$OFFSET
fi
TZ="EST$OFFSET"
date