The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
date manipulation pstanand Shell Programming and Scripting 6 04-03-2008 07:11 AM
need help in time manipulation ali560045 Shell Programming and Scripting 6 03-11-2008 07:41 AM
Manipulation of Date in Shell jnanesh.b Shell Programming and Scripting 1 01-11-2008 10:16 AM
Date Manipulation mgirinath Shell Programming and Scripting 6 04-03-2007 01:25 AM
date manipulation jalburger Shell Programming and Scripting 3 05-10-2004 10:09 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-31-2002
Registered User
 

Join Date: Jan 2002
Posts: 1
Time/date manipulation

hey folks,
been awhile (actaully a long while) since i last touched C. And the 3 books i've read don't really have much about using time.h

Question:
How would i be able to assign a variable the value of the current date minus 2 mths, keeping in mind the yr.
IE. would like to see Nov.31/2001 not Nov.31/2002.

sounds simple enough, but i'm remembering that there's nothing "easy" with C.

thanks,
choice
Reply With Quote
Forum Sponsor
  #2  
Old 02-01-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,658
Code:
      struct timeval tv;
      struct timezone tz;
      struct tm *tm;
      gettimeofday(&tv, &tz);
      tm=localtime(&tv.tv_sec);
      for(n=0; n<2; n++)
            if(!tm->tm_mon--)
                   tm->tm_mon=11,
                   tm->tm_year--;
      fputs(asctime(tm), stdout);
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0