Date time custom formats

Sometime we have to deal with custom date formats, scenarios like you want to append any custom date format in the file name. In such case we can use DateTime.ParseExact() method through .NET Interop:

Ax example can be :

System.Globalization.CultureInfo culture = System.Globalization.CultureInfo::get_InvariantCulture(); utcDateTime dt = System.DateTime::ParseExact( '10/17/2014 0:00', 'MM/dd/yyyy H:mm', culture);

Parameters details about DateTime.ParseExact():

s String

A string that contains a date and time to convert.

format String

A format specifier that defines the required format of s. For more information, see the Remarks section.

provider IFormatProvider

An object that supplies culture-specific format information about s.

Returns

DateTime

An object that is equivalent to the date and time contained in s, as specified by format and provider.

How to find those record that are modified on certain date from a certain table.

When i started working this, i thought it would be task like a click, because i was making logic in my mind to compare the CreatedDateTime field with today’s value (CreatedDateTime >= today()) but when i wrote this i got into trouble, as the compiler is not allowing me and give me error. The error suggest me that i need to convert the date to dateTime then i can use this in select to get my desired result. Not only i need to convert the date to dateTime but i also needs the gets min and max dateTime of todays date.

I open the most important GLOBAL class in AX and luckily i found methods there

datetobeginUtcDateTime(_currDate, _tz),
msdn description of the method: Retrieves a utcdatetime value that represents the beginning of the specified date.

_currDate :The date to retrieve the beginning of.
_tz : The time zone to use to find the start of the date
datetoendUtcDateTime(_currDate, _tz),
msdn description of the method:
Retrieves a utcdatetime value that represents the end of the specified date.

_currDate :The date to retrieve the end of.
_tz : The time zone to use to find the end of the date
After finding the above method to get the min and max datetime for the todays date, i can use them in the select to get userLog record created today.

select * from log
where log.CreatedDateTime >= datetobeginUtcDateTime(today(), DateTimeUtil::getUserPreferredTimeZone()) &&
log.CreatedDateTime <= datetoendUtcDateTime(today(), DateTimeUtil::getUserPreferredTimeZone());