c++dateextracttdatetime

Extract date from date and time


I am using a VCL forms application in C++ Builder.

How can I get just the date from a TDateTime object that has both a date and a time associated with it?

Here is an example:

TDateTime test("25/09/2012 12:00am");

I am after a TDateTime object that has just the following information:

"25/09/2012"

Thanks


Solution

  • You can use DateOf

    However, note that it will return "25/09/2012 00:00" as TDateTime type includes the time, so if you really need TDateTime returned you can't avoid the hour:minute info.

    If you want to extract day/month/year info from TDateTime you can use DecodeDate function