• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1093
  • Last Modified:

read sysdate in visual c++


Hi, i need how read the sysdate in visual c++


Regards

Gerid Garcia
0
yerai
Asked:
yerai
  • 7
2 Solutions
 
List244Commented:
#include <iostream>
#include <windows.h> //Used to get system time
using namespace std;

int main()
{
      SYSTEMTIME Time;
      GetSystemTime(&Time);
      return 0;
}

Then you can access members of Time like:
Time.wDay
Time.wDayOfWeek
Time.wMonth
Time.WYear
0
 
tushar_compCommented:
hi,

i just worked on this concept..
just go through the link below...
u will get all u wanted ...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemtime_str.asp

if its useful ler me know
Tushar
0
 
List244Commented:
I am going to have to disagree with MSDN...

Saturday = 0
Sunday = 1
Monday = 2
Tuesday = 3
Wednesday = 4
Thursday = 5
Friday = 6

And the other members which will appear with Time. are as expected.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
List244Commented:
Actually... no... MSDN is right on that, what is weird however is that for me at least..
WDay returns day+1 instead of day.
0
 
List244Commented:
Once the time hits 5:00 PM it seems it advances the day.
0
 
List244Commented:
This works better, try this:

#include <iostream>
#include <time.h>
using namespace std;

int main()
{
      time_t Time;
      time(&Time);
      tm *Date;
      Date = localtime(&Time);
      cout << Date->tm_mday << endl; //Day of month
      cout << (Date->tm_mon)+1 << endl; //Returns Months since January or Month-1
      cout << Date->tm_wday << endl; //Days since Sunday (Monday =1...)
      cout << (Date->tm_year)+1900 << endl; //Years since 1900
      cout << Date->tm_isdst << endl; //Is daylight savinsg?
      int HrMil = Date->tm_hour; //Hour(Military)
      if (HrMil > 12)
            HrMil-=12;//Get standard
      cout << Date->tm_hour << ':'; //Hour (Military)
      cout << Date->tm_min << '.'; //Minutes
      cout << Date->tm_sec << endl; //Second
      return 0;
}

That example shows a better date/time method.
0
 
List244Commented:
The solution provided by me at: http://#16679626 and the solution provided by tushar_comp at: http://16679983
both seem to be a little wrong to me.  The solution at: http://#16680050 seems to be better fit.

If you must do a split, I am fine with this, but please select http://#16680050 as the answer.

The previous solutions mine, and the link explaining mine more in depth by Tushar_comp are both lacking in that
the time system seems to be incorrect.  This is explained here: http://#16680000
0
 
List244Commented:
Repost: (Trying to fix those links)

The solution provided by me at: http:#16679626 and the solution provided by tushar_comp at: http:#16679983
both seem to be a little wrong to me.  The solution at: http:#16680050 seems to be better fit.

If you must do a split, I am fine with this, but please select http:#16680050 as the answer.

The previous solutions mine, and the link explaining mine more in depth by Tushar_comp are both lacking in that
the time system seems to be incorrect.  This is explained here: http:#16680000
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now