Tuesday 14 September 2021

Add Date Time Format with timestamp as HH:MM:SS:MS to FileName in D365 FSCM

 Some time we need to add the date timestamp with Mili seconds in the time format (Dynamics _ACTUALS_Sep-2020_20210909_13111510) to our output file, so below code will do it:


class Runnable1

{

    /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

        str     s;

        date    dateValue = DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone());

        

        s = date2Str(dateValue,

                        123,

                        DateDay::None,

                        DateSeparator::Hyphen,

                        DateMonth::Short,

                        DateSeparator::Hyphen,

                        DateYear::Digits4

                      );

        

        int time = timenow();


        System.DateTime dateTime = System.DateTime::get_UtcNow();


        str utcTimeAsStr = dateTime.ToString('HHmmssff');

         // Use this format also and see the difference in timestamp value.

        //str utcTimeAsStr = dateTime.ToString('HHmmssfff');


        str customString = s + "_" + date2Str(DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()),

            321, 

            2,

            DateSeparator::None,

            2,

            DateSeparator::None,

            4)+ "_"+ utcTimeAsStr;


        Info(strFmt("Format: %1", customString));

    }


}



The Output would be:

  1. Format: Sep-2021_20210914_13043935

No comments:

Post a Comment

Insert/Update or remove the default dimension value in D365 FSCM via x++

Use below method to insert/update the dimension values, just pass the parameter values to the method and it will return the updated value: p...