Subtract days to a date in AIX 5.3


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Subtract days to a date in AIX 5.3
# 1  
Old 11-27-2012
Subtract days to a date in AIX 5.3

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.
# 2  
Old 11-28-2012
Use perl:-
Code:
#!/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";

# 3  
Old 11-28-2012
I am using shell script.

#!/bin/sh

Greetings
# 4  
Old 11-28-2012
You can use the "TZ" variable and modify it. Note the difference in the output of these commands (try them out):

Code:
(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
# 5  
Old 11-28-2012
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)
Code:
#!/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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. Shell Programming and Scripting

Subtract a file's modification date with current date

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, In a folder, there are files. I have a script which reads the current date and subtract the modification date of each file. How do I achieve this? Regards, Joe (2 Replies)
Discussion started by: roshanbi
2 Replies

3. Shell Programming and Scripting

Get a given date and subtract it to 5 days ago

Hi all, I have been researching to obtain SSL certification expiry for most of our webistes. For some cases, some hosts where not directly accessible so i finally got a solution working with curl using my proxy. This lists the expiry date which i'm finally looking for. # curl --proxy... (4 Replies)
Discussion started by: nms
4 Replies

4. Solaris

Subtract 2 days from timestamp

Hi, I am running on Solaris 11.3. I have a timestamp in this format date +%Y%m%d%H%M . I found some forums saying to use date --d however that didn't work. Is there a way how I can subtract days from timestamp in that format? Thanks (12 Replies)
Discussion started by: nms
12 Replies

5. Shell Programming and Scripting

Subtract months/days from date

Hi, Can you please let me know code for the below (in korn shell) a) Subtract month(s) from given date b) Subtract day(s) from give date c) Subtract month(s) from given timestamp d) Subtract day(s) from give timestamp (1 Reply)
Discussion started by: tostay2003
1 Replies

6. Shell Programming and Scripting

Subtract 2 date columns in .csv file and get output as number of days

Hi, I have one .csv file. I have 2 date columns present in file, column 2 and column 3. I need to calculate how many days exist between 2 dates. I am trying to subtract date column 2 from date column 3. Eg: my file look likes s.no, Start_date,End_Date 1, 7/29/2012,10/27/2012 2,... (9 Replies)
Discussion started by: Dimple
9 Replies

7. Shell Programming and Scripting

Subtract days from a variable holding date

Hi, could someone help on this.. I have a date in variable procdate="05/30/2009" I would want to Subtract it with 3 or 4 (2 Replies)
Discussion started by: infernalhell
2 Replies

8. UNIX for Advanced & Expert Users

Subtract 2 months from the date

I have the script which appends month and year to the name of the file. Now every time when I append the month-year combination I have to subtract 2 months from the current date and then append it, since we are sending our vendor 2 months prior worth of data eveytime. #! /usr/bin/ksh ... (5 Replies)
Discussion started by: mahekr2000
5 Replies

9. Shell Programming and Scripting

Subtract two date in unix

I Have a long file like this 123122312 05/06/12 123123456 05/06/14 I want to take the difference of dates in two lines & print difference sidewise for the whole long files. Pl help me out. (1 Reply)
Discussion started by: vanand
1 Replies
Login or Register to Ask a Question