Solved

using date functions

Posted on 2002-07-09
3
203 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

  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 …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

777 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