UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old December 18th, 2004, 01:25 AM
amitmidha_dba amitmidha_dba is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 amitmidha_dba User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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)

Reply With Quote
  #2  
Old December 20th, 2004, 07:03 AM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 257 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 23 h 46 sec
Reputation Power: 6
Here is a pointer to an article on the subject:

http://www.samag.com/documents/s=8284/sam0307b/0307b.htm

Reply With Quote
  #3  
Old December 21st, 2004, 08:57 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Previous Date In LInux


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway