Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time and date as double based on 1900 date system

Status
Not open for further replies.

skibum019

IS-IT--Management
Dec 13, 2001
25
US
How do I get the current date and time and format it as a double based on the 1900 date system used in many programs such as MS Excel, etc.?
 
Here is what I use:

Code:
[blue]
int getDateInfo(int option)
{
struct tm *tm_struct;
time_t tm_num;
time(&tm_num);
tm_struct=localtime(&tm_num);
int a=tm_struct->tm_mon+1; [green]//MONTH[/green]
int b=tm_struct->tm_mday; [green]//DAY[/green]
int c=tm_struct->tm_year+1900; [green]//YEAR[/green]

if (option==1) return a;
if (option==2) return b;
if (option==3) return c;
return 0;
}
[/blue]

[green]I forgot why I put the 1900 on the year but I do belive it takes the difference between the current year and 1900, so you would get 104 instead of 2004[/green]

Hope that helps,
-Ron [thumbsup2]

cout << "If you don't know where you want to go, we'll make sure you get taken";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top