Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PROBLEMS WITH DATES

Posted on 1998-10-22
1
Medium Priority
?
180 Views
Last Modified: 2010-04-15
Could anybody tell me how to get the date in format 'yyyymmdd' from a week ago to the actual date?

By instance, today´s date
Example: 19981022

I´interested to know the date a week ago.
19981015

The problem comes with the first days of the month, year...

Thanks very much
0
Comment
Question by:carlos0007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 400 total points
ID: 1253732
(1) Convert the date (X) you're working with, into time since some reference point.
     Using standard time.h header, you can do this by filling in struct tm and calling mk_time (which will return a value of type time_t which is seconds since 1970).  Keep this
     value

(2) Subtract 60*60*24*7 (one week's seconds) from the time_t you just got

(3) Call gmtime with the result of (2) to get another struct tm, call this pLastWeek

(4) Output, example:

printf( "%04d%02d%02d", pLastWeek->tm_year, (pLastWeek->tm_mon)+1, pLastWeek->tm_mday ) ;

This will work provide last week was after 1 Jan 1970


0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question