Solved

PROBLEMS WITH DATES

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now