How can I log the date when a program was compiled in visual studio?

Hi,

I am writing a VS 2005 native c++ console application. Each time I run it, I would like it to log to file the date on which it was compiled.  How can I do this?  

I know how to log stuff to files... the thing I can't figure out is how to obtain a date once at compile time such that it remains a runtime constant.

thanks
highqllcAsked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
You could use the __DATE__ and __TIME__ macro's. As example :

        printf("%s %s\n", __DATE__, __TIME__);
0
 
Infinity08Commented:
or more C++-y :

        std::cout << __DATE__ << " " << __TIME__ << std::endl;
0
 
jkrConnect With a Mentor Commented:
The predefined macro __DATE__ allowes to do that, e.g.

printf("Module compiled on %s", __DATE__);
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
waysideConnect With a Mentor Commented:
Use the __DATE__ macro. Add something like

char *compileDate = __DATE__;

in your code.
0
 
jkrConnect With a Mentor Commented:
0
 
highqllcAuthor Commented:
Awesome. Perfect.

How on earth do I divy out points here? :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.