By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,303 Members | 1,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,303 IT Pros & Developers. It's quick & easy.

system date

P: n/a
Wen
Is it easy to get the system date in c++?
Somethings like in SQL or VB?
--

Regards,
Wen
Jul 22 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"Wen" <We************@hccnet.nl> wrote...
Is it easy to get the system date in c++?
Somethings like in SQL or VB?


// get the system calendar time
std::time_t tt = std::time(0);
// convert it into tm struct
std::tm ttm = *std::localtime(&tt);
// extract the values for day, month, year
int mday = ttm.tm_mday;
...

Victor
Jul 22 '05 #2

P: n/a
Wen
Thank you Victor,

Your codes are to difficult for me.

Best Regards,
Wen

"Victor Bazarov" <v.********@comAcast.net> schreef in bericht
news:nsqCb.324347$Dw6.1094815@attbi_s02...
"Wen" <We************@hccnet.nl> wrote...
Is it easy to get the system date in c++?
Somethings like in SQL or VB?


// get the system calendar time
std::time_t tt = std::time(0);
// convert it into tm struct
std::tm ttm = *std::localtime(&tt);
// extract the values for day, month, year
int mday = ttm.tm_mday;
...

Victor

Jul 22 '05 #3

P: n/a
On Fri, 12 Dec 2003 23:19:20 +0100 in comp.lang.c++, "Wen"
<We************@hccnet.nl> was alleged to have written:
Thank you Victor,
Your codes are to difficult for me.


Each thing that follows "std::" is a name of something in the standard
library. Using Victor's post for clues, look up the names "time_t",
"time()", "localtime()" etc. in the index of your favorite reference.

See also section 13.12 thru 13.14 in Steve Summit's C FAQ. It is always
good to check the FAQ before posting. You can get the FAQ at:
http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #4

P: n/a

"David Harmon" <so****@netcom.com> schreef in bericht
news:3f***************@news.west.earthlink.net...
On Fri, 12 Dec 2003 23:19:20 +0100 in comp.lang.c++, "Wen"
<We************@hccnet.nl> was alleged to have written:
Thank you Victor,
Your codes are to difficult for me.


Each thing that follows "std::" is a name of something in the standard
library. Using Victor's post for clues, look up the names "time_t",
"time()", "localtime()" etc. in the index of your favorite reference.

See also section 13.12 thru 13.14 in Steve Summit's C FAQ. It is always
good to check the FAQ before posting. You can get the FAQ at:
http://www.eskimo.com/~scs/C-faq/top.html

Thanks David!

I've token a look in the C FAQ and found also these code's. (q20.31) But
still I dont kwow how to use it.
I'm a starter, use C++ about 2 months.
My compiler (dev c++, bloodshed 4.981) doenst know <time_t>, where can I get
the time libary?

Which include do I need? Is this a void of int ?

dayofweek(y, m, d) /* 0 = Sunday */
int y, m, d; /* 1 <= m <= 12, y > 1752 or so */
{
static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

Best Regards,
Wen
Jul 22 '05 #5

P: n/a
"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> wrote...

"David Harmon" <so****@netcom.com> schreef in bericht
news:3f***************@news.west.earthlink.net...
On Fri, 12 Dec 2003 23:19:20 +0100 in comp.lang.c++, "Wen"
<We************@hccnet.nl> was alleged to have written:
Thank you Victor,
Your codes are to difficult for me.
Each thing that follows "std::" is a name of something in the standard
library. Using Victor's post for clues, look up the names "time_t",
"time()", "localtime()" etc. in the index of your favorite reference.

See also section 13.12 thru 13.14 in Steve Summit's C FAQ. It is always
good to check the FAQ before posting. You can get the FAQ at:
http://www.eskimo.com/~scs/C-faq/top.html

Thanks David!

I've token a look in the C FAQ and found also these code's. (q20.31) But
still I dont kwow how to use it.
I'm a starter, use C++ about 2 months.


What book are you reading?
My compiler (dev c++, bloodshed 4.981) doenst know <time_t>, where can I get the time libary?

Which include do I need? Is this a void of int ?


This is definitely a void of int. Use <get_yourself_a_good_C_book>
include. Once you used it, open the book and study. Nothing will
replace a good study.
Jul 22 '05 #6

P: n/a
Hallo Victor,
That boek we has a Dutch name, in English is something like "to the battle
in C++"
I had about 25 hours lesson, now I must make a program for end
"examination" and I've got 2 weeks time to do it.
So, I need the help of this group.
Thanks voor your tip. If I've got more time I'll get a good c book.
Best Regards
Wen

"Victor Bazarov" <v.********@comAcast.net> schreef in bericht
news:XDHCb.530486$HS4.4053055@attbi_s01...
"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> wrote...

"David Harmon" <so****@netcom.com> schreef in bericht
news:3f***************@news.west.earthlink.net...
On Fri, 12 Dec 2003 23:19:20 +0100 in comp.lang.c++, "Wen"
<We************@hccnet.nl> was alleged to have written:
>Thank you Victor,
>Your codes are to difficult for me.

Each thing that follows "std::" is a name of something in the standard
library. Using Victor's post for clues, look up the names "time_t",
"time()", "localtime()" etc. in the index of your favorite reference.

See also section 13.12 thru 13.14 in Steve Summit's C FAQ. It is always good to check the FAQ before posting. You can get the FAQ at:
http://www.eskimo.com/~scs/C-faq/top.html

Thanks David!

I've token a look in the C FAQ and found also these code's. (q20.31) But
still I dont kwow how to use it.
I'm a starter, use C++ about 2 months.


What book are you reading?
My compiler (dev c++, bloodshed 4.981) doenst know <time_t>, where can I

get
the time libary?

Which include do I need? Is this a void of int ?


This is definitely a void of int. Use <get_yourself_a_good_C_book>
include. Once you used it, open the book and study. Nothing will
replace a good study.

Jul 22 '05 #7

P: n/a
"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> wrote...
Hallo Victor,
That boek we has a Dutch name, in English is something like "to the battle
in C++"
I had about 25 hours lesson, now I must make a program for end
"examination" and I've got 2 weeks time to do it.
So, I need the help of this group.
Thanks voor your tip. If I've got more time I'll get a good c book.


Kees,

A C++ book is unlikely to cover the C Standard library in depth
needed for your program. That's why I strongly recommend a C
book (even if you haven't got any time, find the time and visit
your favourite computer book shop).

Here is my code expanded to fully executable form:

#include <ctime>
#include <iostream>

int main()
{
std::time_t tt = std::time(0);
std::tm ttm = *std::localtime(&tt);
std::cout << "Today is day " << ttm.tm_mday
<< " of the month " << ttm.tm_mon + 1
<< " of the year " << ttm.tm_year + 1900
<< std::endl;
}

The same program in C would look like this

#include <time.h>
#include <stdio.h>

int main()
{
time_t tt = time(0);
struct tm ttm = *localtime(&tt);
printf("Today is day %d of the month %d of the year %d\n",
ttm.tm_mday, ttm.tm_mon + 1, ttm.tm_year + 1900);
return 0;
}

Now, if it doesn't give you enough information to proceed, you
will _have_ to ask more particular questions.

Victor
Jul 22 '05 #8

P: n/a
Wen
Victor,
Thank you very much!!Your code works!

Which book will you recommen, do you have a ISBN for me?
Best Regards,
Wen
"Victor Bazarov" <v.********@comAcast.net> schreef in bericht
news:J7MCb.382941$275.1236876@attbi_s53...
"Kees Hoogendijk" <ni********@haalditweg-hcopleidingen.nl> wrote...
Hallo Victor,
That boek we has a Dutch name, in English is something like "to the battle in C++"
I had about 25 hours lesson, now I must make a program for end
"examination" and I've got 2 weeks time to do it.
So, I need the help of this group.
Thanks voor your tip. If I've got more time I'll get a good c book.


Kees,

A C++ book is unlikely to cover the C Standard library in depth
needed for your program. That's why I strongly recommend a C
book (even if you haven't got any time, find the time and visit
your favourite computer book shop).

Here is my code expanded to fully executable form:

#include <ctime>
#include <iostream>

int main()
{
std::time_t tt = std::time(0);
std::tm ttm = *std::localtime(&tt);
std::cout << "Today is day " << ttm.tm_mday
<< " of the month " << ttm.tm_mon + 1
<< " of the year " << ttm.tm_year + 1900
<< std::endl;
}

The same program in C would look like this

#include <time.h>
#include <stdio.h>

int main()
{
time_t tt = time(0);
struct tm ttm = *localtime(&tt);
printf("Today is day %d of the month %d of the year %d\n",
ttm.tm_mday, ttm.tm_mon + 1, ttm.tm_year + 1900);
return 0;
}

Now, if it doesn't give you enough information to proceed, you
will _have_ to ask more particular questions.

Victor

Jul 22 '05 #9

P: n/a
"Wen" <We************@hccnet.nl> wrote...
Which book will you recommen, do you have a ISBN for me?


Since it's a C book, I do not know the most recent advances
in the field of C programming and its description in books.
Please consider asking in comp.lang.c (and looking in their
FAQ first, then in archives, I am sure the "best book on C"
question has been asked more than once already) and visiting
http://www.accu.org for book reviews.

Victor
Jul 22 '05 #10

P: n/a
Thank you once more, Victor.
I'll!
Best Regards,
Wen
"Victor Bazarov" <v.********@comAcast.net> schreef in bericht
news:z73Db.48978$8y1.196444@attbi_s52...
"Wen" <We************@hccnet.nl> wrote...
Which book will you recommen, do you have a ISBN for me?


Since it's a C book, I do not know the most recent advances
in the field of C programming and its description in books.
Please consider asking in comp.lang.c (and looking in their
FAQ first, then in archives, I am sure the "best book on C"
question has been asked more than once already) and visiting
http://www.accu.org for book reviews.

Victor

Jul 22 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.