I have a plugin which has a datepicker in the post, and saves this date as unix epoch to visitor-date. Problem is that it always saves everything as the same time 00:00:00 and I want it to be saved as 23:59:59.

The code looks like this:

if ( isset( $_POST['vs-date'] ) ) {
    update_post_meta( $post_id, 'visitor-date', sanitize_text_field(strtotime( $_POST['vs-date'] ) ) );

What it does it that it check if ´vs-date´ is set, and if it is, it converts it to unix epoch format and saves it to the ´visitor-date´ metakey.

Is it possible to add +86399 seconds to the epoch before saving it to ´visitor-date´?



update_post_meta( $post_id, 'visitor-date', sanitize_text_field(strtotime('+23 hours + 59 minutes + 59 seconds', strtotime( $_POST['vs-date'] ) ) ) );
  • This would do it. However, you mentioned this is done in a plugin. Is it a plugin that you may possibly need to update in the future? If so, you should probably grock through it to find where this action is hooked to in WP and hook a function to a later priority (so it fires after the plugin's process) to update the field with the appropriate date/time. Otherwise you'll just be reapplying your hack every time you update the plugin. – butlerblog Nov 2 '18 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.