Skip to content

Instantly share code, notes, and snippets.

@indikatordesign
Last active December 5, 2022 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indikatordesign/272a9fd869027c7722526b460aa103dc to your computer and use it in GitHub Desktop.
Save indikatordesign/272a9fd869027c7722526b460aa103dc to your computer and use it in GitHub Desktop.
WordPress - Get the next 12 am timestamp (sheduled actions etc.)
<?php
/**
* Do not allow direct access
*
* @since 1.0
*/
if ( ! defined( 'ABSPATH' ) ) die( 'Nothing to find Ma\'am..' );
/**
* Your Plugin Name - Controller Helpers
*
* @since 1.0
*/
if ( ! class_exists( 'controllerHelpers' ) )
{
final class controllerHelpers
{
/**
* Get the next 12:00 am timestamp
*
* @since 1.0
*/
public function twelveTimestamp()
{
$time = time();
$hour = (int) date( 'H', $time );
if ( $hour >= 11 ) // to be sure
$add = 24 - $hour + 2; // next day
if ( isset( $add ) )
$setTarget = date( 'Y-m-d', $time + ( $add * HOUR_IN_SECONDS ) ) . ' 12:00:00';
else
$setTarget = date( 'Y-m-d', $time ) . ' 12:00:00';
return DateTime::createFromFormat( 'Y-m-d H:i:s', $setTarget )->getTimestamp();
} // end twelveTimestamp
} // end class
} // end if
$timestamp = ( new controllerHelpers )->twelveTimestamp();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment