Skip to main content

Notifications

Announcements

No record found.

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 232

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.

  • Suggested answer
    Bilal Haider Profile Picture
    Bilal Haider 232 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.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 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

  • Bilal Haider Profile Picture
    Bilal Haider 232 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.

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 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
    Bilal Haider 232 on at
    RE: Removing DateTime value from a field of a table record using code

    It is BC 1416 OnPrem

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 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
    Bilal Haider 232 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
    Suresh Kulla 44,656 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....

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans