Insert future date in a c++ program

How to insert date automatically in a c++ program.

Page 1 of 1

3 Replies - 4373 Views - Last Post: 22 October 2009 - 07:47 AM Rate Topic: -----

#1 aakash.kedari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-October 09

Insert future date in a c++ program

Post icon  Posted 22 October 2009 - 06:51 AM

I am trying to figure out how to insert date in a c++ program but the thing is that I cannot actually get it. I am creating a program to manage a school library and want to learn how to insert a future date automatically in the program. Please help me. Thanks in advance!!!!


void issue_a_book()
{  char author[25], book[25], issdate[9], retdate[9];
   int acc_no;
   _strdate(issdate);
   cout<<"\n\t\tIssue a Book";
   cout<<"\n\nPlease enter the details...";
   cout<<"\nDate of Issue: ";
   cout<<issdate;
   cout<<"\nAuthor's Name: ";
   gets(author);
   cout<<"Book Name: ";
   gets(book);
   cout<<"Accession No.: ";
   cin>>acc_no;
   cout<<"Due Date: ";
   cout<<										   //( i have a problem in this line )
 getch();
 }


This post has been edited by aakash.kedari: 22 October 2009 - 06:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Insert future date in a c++ program

#2 Ancient Dragon  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 81
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: Insert future date in a c++ program

Posted 22 October 2009 - 06:56 AM

The functions in time.h (or ctime for c++ programs) are useful for that. The steps needed to create a future date are:
  • Set up a struct tm with the current date -- call localtime() to get a pointer to it.
  • increase the day structure member -- tm_mday -- by the number of days into the future.
  • Call mktime() to normalize the structure

Was This Post Helpful? 0
  • +
  • -

#3 aakash.kedari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-October 09

Re: Insert future date in a c++ program

Posted 22 October 2009 - 07:10 AM

I could not actually get what you told. Can you explain it in a bit simpler way.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: Insert future date in a c++ program

Posted 22 October 2009 - 07:47 AM

Time to learn how to read and use documentation and critical thinking.

OK, so you're using _strdate. MSDN has a page on _strdate. Explains how to use it and all.

Now, if you scroll to the bottom of that page, you'll see a section See Also. Underneath here you'll find links to the time functions available to you, including those to which Ancient Dragon pointed you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1