Thread: How do you get the current date?

  1. #1
    cerial-killer
    Guest

    Question How do you get the current date?

    Are there any functions that return the current day month and year as integer.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    OS? Compiler?

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Have a look at the ctime functions here.

    Note: for tm_mon, jan = 0, feb = 1, ..., dec = 11

    Code:
    #include <iostream>
    #include <ctime>
    
    int main( void ) {
    
    	tm * curTM;
    	time_t temp = time( NULL );
    	curTM = localtime( &temp );
    
    	std::cout<<"Day: "<<curTM->tm_mday<<" Month: "<<curTM->tm_mon<<" Year: "<<curTM->tm_year + 1900<<std::endl;	
    
    	return 0;
    
    }
    Last edited by XSquared; 03-18-2003 at 02:03 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    GetSystemTime() on windows is pretty good and easy. but then you still haven't said what platform you're on
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    cerial-killer
    Guest

    Lightbulb THANKS

    Thx allot, XSquared. Works perfectly.
    I was trying to mess around with time.h, but that
    didn't lead anywhere. You just saved me about 2 hours of programming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  2. Problem with simple case statements
    By shoobsie in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 08:39 AM
  3. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  4. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM
  5. How do I get the current date in my code?
    By FromHolland in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2003, 01:37 PM