473,651 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

system date

Wen
Is it easy to get the system date in c++?
Somethings like in SQL or VB?
--

Regards,
Wen
Jul 22 '05 #1
10 8241
"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
Wen
Thank you Victor,

Your codes are to difficult for me.

Best Regards,
Wen

"Victor Bazarov" <v.********@com Acast.net> schreef in bericht
news:nsqCb.3243 47$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
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

"David Harmon" <so****@netcom. com> schreef in bericht
news:3f******** *******@news.we st.earthlink.ne t...
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
"Kees Hoogendijk" <ni********@haa lditweg-hcopleidingen.n l> wrote...

"David Harmon" <so****@netcom. com> schreef in bericht
news:3f******** *******@news.we st.earthlink.ne t...
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
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
"examinatio n" 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.********@com Acast.net> schreef in bericht
news:XDHCb.5304 86$HS4.4053055@ attbi_s01...
"Kees Hoogendijk" <ni********@haa lditweg-hcopleidingen.n l> wrote...

"David Harmon" <so****@netcom. com> schreef in bericht
news:3f******** *******@news.we st.earthlink.ne t...
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
"Kees Hoogendijk" <ni********@haa lditweg-hcopleidingen.n l> 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
"examinatio n" 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
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.********@com Acast.net> schreef in bericht
news:J7MCb.3829 41$275.1236876@ attbi_s53...
"Kees Hoogendijk" <ni********@haa lditweg-hcopleidingen.n l> 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
"examinatio n" 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
"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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3665
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style of date formatting (RFC 822). I have been using a variation of RFC 1123 (just change the time zone to an offset, i.e. "-0800"). It seems to be writing okay, but it's failing to parse. I've tried changing the regional & language settings in my...
2
500
by: Ben | last post by:
I have several pages written in aspx, but sometime the aspx page return the following error. And it hapeen, the whole web application gives this error, that means all the aspx files get affected. Any ideas? Here is the error: Server Error in '/' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An unhandled exception occurred...
0
5647
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
11
12996
by: Mike9900 | last post by:
How can I get the real system date/time if the user fakes the date, for example by setting the system date back. -- Mike
3
2980
by: Carlos Lozano | last post by:
I have requirement to pause the system clock until a certain event (Win XP). Then the clock will be resumed to the real time. I think it can be done using core functions and/or redirecting the time/date call to a temporary service routines, then redirect to the original. I will appreciate any ideas to go in the right direction. Carlos
1
4663
by: shyam vashista | last post by:
i have problem in validation check for system date with server date problem::: If i change my system date as september 30, 2006 and use validation for filling form as current date as oct30, 2006 than it will ask me for check ur entry date but wen i fill form that time date is oct 30, 2006 so how to solve this problem ? how to check date with server date? it is not compulsary that system date by which i am filling form date is same...
5
3206
by: adie | last post by:
hi, can anyone help me out with this. the requirement is to display a time (any time) from a distinct timezone (lets say EST) on a webpage but to make available the conversion to the user local timezone based on the users system time (presume the browser headers contain this) Guess im after a small function that takes a time and converts it to another time based on the users browser system time
15
2592
by: iffa n wanie | last post by:
Develop a library information system that provides the following functionalities: a) Add New Patron b) Search Patron c) Check Out Book The patron ID is unique and is generated automatically by the system. Any patron can borrow at most three (3) books. The period of loan is two (2) weeks. Your program will retrieve the computer’s current date to be used as the date a book is borrowed and calculate the due date automatically. You can...
4
7404
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system date is retrieved like this: curDt = new Date();
2
2348
by: samvb | last post by:
Hi, I have just finished a program that uses ms access and depends on system date to do certain things. just when i was testing it, a friend suggested that i change system date to see how it reacts. And it totally failed if the system date changes. I have written a small module that can save me from this errors upon the user's request i.e. the user clicks a button to reset the date using my program. during the reseting process, i fix any date...
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.