Solved

using date functions

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 55
c++ substatte a varabe for a string in a LPCTSTR statment 8 83
White board coding practice 3 80
How can i compile this github project?? 2 76
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

867 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

25 Experts available now in Live!

Get 1:1 Help Now