Solved

using date functions

Posted on 2002-07-09
3
210 Views
Last Modified: 2010-04-01
I need to put system date details in either 1 or 3 variables
ie
date_today = yymmdd

or

date_year = yy
date_month = mm
date_day = dd

thanks
0
Comment
Question by:Karls
  • 2
3 Comments
 
LVL 8

Expert Comment

by:mnashadka
ID: 7142261
You can use time(NULL) to get a time_t, then localtime to get a struct tm representing the time:
time_t now = time(NULL);
struct tm *time_data = localtime(&now);

Then you can use the tm_mon (the month starts at 0, so you'll probably add 1), tm_year, and tm_mday struct elements to get the data that you need.
0
 
LVL 30

Expert Comment

by:Axter
ID: 7142282
Use the strftime function
0
 
LVL 30

Accepted Solution

by:
Axter earned 60 total points
ID: 7142298
Example:

time_t ltime =      time(NULL);
char DestinationBuffer[64];
strftime(DestinationBuffer, sizeof(DestinationBuffer), "%y%m%d", gmtime(&ltime));
printf("The date is %s\n", DestinationBuffer);
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

860 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