?
Solved

using date functions

Posted on 2002-07-09
3
Medium Priority
?
224 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
[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
  • 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 240 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

Industry Leaders: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

752 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