Solved

PROBLEMS WITH DATES

Posted on 1998-10-22
1
175 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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

739 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