2

I am using C++ Builder and am creating a GUI application using the TDateTime data type.

When I use the MonthOf() method on a TDateTime object, I am getting a value that is 1 month behind from the actual month of the TDateTime object.

Why is this? Is this a bug?

Mark Garcia
  • 17,424
  • 4
  • 58
  • 94
user1690531
  • 231
  • 1
  • 6
  • 17
  • 2
    Can you write an example with, say, the TDateTime value (numeric and in text) and what you expect MonthOf to give, and what it actually gives? [MonthOf is supposed to return a value between 1 and 12](http://docwiki.embarcadero.com/Libraries/XE3/en/System.DateUtils.MonthOf), so if you're assuming it's 0-based you will need to account for a difference of 1. – David Oct 11 '12 at 10:25

1 Answers1

1

If you want to get current month try this code:

TDateTime dt = Now();
CurMonth=StrToInt(FormatDateTime("mm", dt));
Denis Ermolin
  • 5,530
  • 6
  • 27
  • 44