read sysdate in visual c++


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


Regards

Gerid Garcia
yeraiAsked:
Who is Participating?
 
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:
#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
 
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.