0

I declared a variable named date with type DateTime in Visual Studio 2017 but when I try to access DateTime::DayOfWeek, I cannot do so. I was trying to give date that value like this

    DateTime dayy;
    dayy = DateTime::DayOfWeek;

But I get error

A nonstatic member reference must be relative to a specific object

  • What is `DateTime::DayOfWeek`? Is it a non-static member variable? What would its value be? Perhaps you should take a few steps back, [get a few good books to read](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) and start over? – Some programmer dude Apr 03 '18 at 06:54
  • 2
    I'm confused, is this C++ or C#? `DateTime` is a .NET thing. – acraig5075 Apr 03 '18 at 06:55
  • I am using C++ in Visual Studio @acraig5075 windows forms –  Apr 03 '18 at 06:56
  • Are you perhaps using [C++/CLI](https://en.wikipedia.org/wiki/C%2B%2B/CLI)? Then please edit your question to correct the tags. – Some programmer dude Apr 03 '18 at 06:59
  • Try `DateTime.DayOfWeek` that's the .NET way of accessing a property, but I'm just guessing because I'm still confused as to how you're doing this. – acraig5075 Apr 03 '18 at 07:00

1 Answers1

0

Try to use time.h

#include <time.h>

time_t timeObj = time(nullptr);
tm aTime;
localtime_s(&aTime, &timeObj);
std::cout << aTime.tm_wday;
VitkorAl
  • 44
  • 5