Solved

PROBLEMS WITH DATES

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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 opening and reading files in the C programming language.

821 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