Solved

PROBLEMS WITH DATES

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

Technology Partners: 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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

636 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