# Getting and writing the date

## Recommended Posts

I know some functions that do this but what is the easiest way to get in the end smth. that looks like: Day is Wednesday Month is May Year is 2004

##### Share on other sites
Which language? Assuming C or C++, the simplest (but not necessarily shortest) way is to use 'localtime' to get the time, then use a switch/case statement on the values. Probably the shortest (but far from simplest) approach in C++ is to use the Boost Date/Time library.

##### Share on other sites
Simple Google-ing of ""C++" date" found this.

EDIT: That too...

##### Share on other sites
If you're willing to use .NET functions, look into the DateTime class.

Other than that, a search on MSDN should give you some good Win32 options.

EDIT: Wow, no one responds for an hour, then when I want to everyone else jumps on... [smile]

##### Share on other sites
If you don't want to use an existing libary, there are lots of date/time classes out there. It is one the the "learning" classes.

theTroll

##### Share on other sites
You can get the date and time with two simple ANSI C function calls.

#include <stdio.h> /* Includes printf */#include <time.h>  /* Includes the time functions */main(){    time_t current_time;                        /* Create a time_t variable */    if((time(&current_time)) != -1)             /* If time is available */    {        printf("%s",ctime(&current_time));      /* Print time converted to local time */    }    else                                        /* If time is not available */        printf("Error: Time is not available"); /* Print error */    return 0;}

Hope that helps.

Sifr

[Edited by - Sifr on April 30, 2006 2:06:01 PM]

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627648
• Total Posts
2978393

• 10
• 12
• 22
• 13
• 33