Monday, January 10, 2011

Using UTCDateTime Variables in Select Statements

Sometimes, you need to be able to compare a date with a UTC Date Time variable. This is how you use it in a select statement. This statement looks for sales table records that were created on 12/7/2010.
The trick to this is that the function dateToBeginUTCDateTime() is not visible to the users through the normal right click method finding technique. You just have to remember what it is and know how to use it. I always forget the name so this is my personal reminder for the next time I inevitably forget.

SalesTable salesTable;
Date daxDate = str2date('12/7/2010', 2);
TimeZone daxTimeZone = DateTimeUtil::getUserPreferredTimeZone();
UTCDateTime daxDateTime = dateToBeginUTCDateTime(daxDate,daxTimeZone);
;
while select salesTable
     where salesTable.createdDateTime == daxDateTime
{
     info (strFmt("%1 - %2", salesTable.SalesId, salesTable.CustAccount));
}

or, you can replace the daxDateTime variable with a one-liner like this:
datetobeginUtcDateTime(str2date('12/7/2010',2),DateTimeUtil::getUserPreferredTimeZone())

No comments:

Post a Comment