How To Add Current Timestamp Column?

Support MB Custom Table How To Add Current Timestamp Column?Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #33800
    Ranadeep GhoseRanadeep Ghose
    Participant

    I am new here. I have a custom table where my CPT data is being saved. However, I want to add two DATETIME fields for my database columns Created_On and Modified_On. The idea is to insert the current datetime in Created_On column when the form is being submitted the first time and then if it is edited/modified then current datetime to only update the Modified_On column without updating the Created_On column.

    I am somehow missing something. Can someone please help me with the right direction how to achieve this?

    #33818
    Long NguyenLong Nguyen
    Moderator

    Hi Ranadeep,

    You can follow this documentation to add two columns to the existing custom table https://docs.metabox.io/extensions/mb-custom-table/#using-existing-tables

    Then when saving the post, you can check if the field Created_On has value, then update the time for the field Modified_On.

    Refer to this documentation https://developer.wordpress.org/reference/functions/current_time/
    https://docs.metabox.io/actions/#rwmb_after_save_post

    #33854
    Ranadeep GhoseRanadeep Ghose
    Participant

    Ok. Yes I could make it work that way. Thank you for the support.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.