Date Format without Time for Midnight Values while using PC's Regional Settings

Posted by: Luke on 9 March 2023, 3:22 pm EST

    • Post Options:
    • Link

    Posted 9 March 2023, 3:22 pm EST

    Is there a setting that can be applied for all reports, or if not, each report, or if not, each control so that if the date doesn’t have time, the time portion isn’t shown.

    Ideally, it would use the PC’s regional settings for setting date/time when time exists, and just the date portion if the time is 12:00:00 AM.

    Or do we need to write code for every date field on every record’s format event to support this for each control. Any suggestions would be appreciated.


  • Posted 12 March 2023, 7:50 pm EST

    Hi Luke,

    Unfortunately, it is not possible to apply a setting to all the reports or a single report to only show the date/time when time exists (i.e. time is not equal to 12:00:00 AM).

    However to be used in a control, you may write a code in your report’s script to accept a DateTime value, and compare if the time is equal to ‘12:00:00 AM’ if yes, return only the Date part using ‘DateTime.ToShortDateString()’ else return the whole Date as a string.

    You may now call this method in any of your control using ‘=Code.YourMethod(DateTimeValue)’ and it will return the date value as per your condition.

    Please find attached a report sample implementing the same.



  • Posted 13 March 2023, 9:07 am EST

    Thank you for your suggestion and sample report. In my case, I had to convert it to C#. No big deal.

    But we have controls that are data bound with a field assignment on its DataField property.

    Tried to assign the DataField property to = Function(DataField) but that didn’t work.

    So I created a Detail_Format event and changed the Text property of each date control to convert it. That seems to work, but is that the right approach or can it be assigned on the Property sheet rather than creating events for each section?

  • Posted 13 March 2023, 6:25 pm EST

    Hi Luke,

    It seems like you are working with SectionReports, please note the ‘=Code.FunctionName()’ can be used with Page/RDL Reports.

    For SectionReports your approach has no issues, you can handle section events to format and assign data to your controls.

    However, as it is a lengthy process for your use case, you can also directly assign an expression in the ‘DataField’ property of your control such as

    =(DateValue.TimeOfDay.ToString() == "00:00:00") ? DateValue.ToShortDateString() : DateValue.ToString();

    Please find attached a sample implementing your use case in a SectionReport.



Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels