web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Removing DateTime value from a field of a table record using code

(0) ShareShare
ReportReport
Posted on by 408

I want to remove datetime values from a field of a table using code. 

There is already some value in the datetime field. If I want to make that field empty.

Methods I have tried:

1.   RandomTable."Approval Date Time" := 0DT;

      RandomTable.Modify;

2.  CLEAR(RandomTable."Approval Date Time");

If I try code like below then it updates the field with current datetime but I am unable to clear its value using above two methods.

 

RandomTable."Approval Date Time" := CURRENTDATETIME;

RandomTable.Modify;

Any help in this regard is highly appreciable.

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: Removing DateTime value from a field of a table record using code

    After you run the first code what value are you seeing in that field? usually on SQL side there is a default value for those fields something like 1753....

  • Bilal Haider Profile Picture
    408 on at
    RE: Removing DateTime value from a field of a table record using code

    After running first code I see the same old value that is populated before by using the CURRENTDATETIME function.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: Removing DateTime value from a field of a table record using code

    That is not possible unless there is another code which is overwriting it again. What version you are using?

  • Bilal Haider Profile Picture
    408 on at
    RE: Removing DateTime value from a field of a table record using code

    It is BC 1416 OnPrem

  • Verified answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: Removing DateTime value from a field of a table record using code

    DateTime.gif

    Tested this on BC14 and I don't see any issue. I just used the below code under update action

    "Created On" := 0DT;
    MODIFY;

  • Bilal Haider Profile Picture
    408 on at
    RE: Removing DateTime value from a field of a table record using code

    Hi,

    Thanks Suresh for going beyond for helping me. I acknowledge it.

    But I am using C/AL code in background to update these fields without getting user input. But I will check my code again.

  • Suggested answer
    Suresh Kulla Profile Picture
    50,233 Super User 2025 Season 2 on at
    RE: Removing DateTime value from a field of a table record using code

    The above example is also in CAL on BC 14

  • Suggested answer
    Bilal Haider Profile Picture
    408 on at
    RE: Removing DateTime value from a field of a table record using code

    Yes, this way it has worked. I was trying to change multiple records that are coming to filter like this:

    TableVariable.MODIFYALL(DateTime,0DT);

    Now I have loop over all filtered records and used:

    TableVariable.DateTime := 0DT;

    TableVariable.Modify;

    But I am still confused why it was not working for all filtered using ModifyAll because all other fields are updating correctly using ModifyAll.

    Anyways, it worked for now and thanks for your answer. I have verified that.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,255

#2
Sumit Singh Profile Picture

Sumit Singh 2,665

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,401

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans