Board index » cppbuilder » Identify the first day of the current year and month

Identify the first day of the current year and month


2005-05-04 10:39:16 PM
cppbuilder19
Hi
I have a table that contains orders information.
I need to filter the table to add all orders:
a) between the start of the year (Jan 1 of the current year)
and the current date (today) Year-to-date
b) between the start of the current month (Day 1) and the
current date today) month-to-date
Is there a way to identify the first day of the current year and
the first day of the current month, so I can use them in the
filtering codes????
I use the following code to filter the table between two
user selectable dates and would like to change it to filter the
year-to-date and the month-to-date
if (DateTimePicker3->Date>DateTimePicker2->Date)
{
Table1->Filtered = false;
Table1->Filter = "Date>'" + DateTimePicker2->DateTime.FormatString(ShortDateFormat) + "'" + "AND Date < '" + DateTimePicker3->DateTime.FormatString(ShortDateFormat) + "'";
Table1->Filtered = true;
}
thanks in advance
Rob
 
 

Re:Identify the first day of the current year and month

Quote
Is there a way to identify the first day of the current year
and
the first day of the current month, so I can use them in the
filtering codes????
If I understood well, the following example does what you need:
Word Y, M, D;
TDateTime DTNow = Now();
DecodeDate(DTNow, Y, M, D);
TDateTime FirstDayOfCurrentYear = EncodeDate(Y, 1, 1);
TDateTime FirstDayOfCurrentMonth = EncodeDate(Y, M, 1);
Maybe there are easier ways...
Steve.
 

Re:Identify the first day of the current year and month

Steve Aletto wrote:
Quote
Maybe there are easier ways...

Steve.


TDateTime FirstDayOfMonth = RecodeDay(Date(),1);
TDateTime FirstDayOfYear = RecodeMonth(FirstDayOfMonth,1);
 

{smallsort}

Re:Identify the first day of the current year and month

Quote
TDateTime FirstDayOfMonth = RecodeDay(Date(),1);
TDateTime FirstDayOfYear = RecodeMonth(FirstDayOfMonth,1);
Both available since BCB6 though.
Steve.