bp_dd_get_random_date( int $days_from = 30, int $days_to )

Get a random date between some days in history.

Description

If [30;5] is specified – that means a random date between 30 and 5 days from now.

Parameters

$days_from

(int) (Optional)

Default value: 30

$days_to

(int) (Required)

Return

(string)

Source

File: bp-core/bp-core-tools-default-data.php

function bp_dd_get_random_date( $days_from = 30, $days_to = 0 ) {
	// $days_from should always be less than $days_to
	if ( $days_to > $days_from ) {
		$days_to = $days_from - 1;
	}

	$date_from = new DateTime( 'now - ' . $days_from . ' days' );
	$date_to   = new DateTime( 'now - ' . $days_to . ' days' );

	return date( 'Y-m-d H:i:s', mt_rand( $date_from->getTimestamp(), $date_to->getTimestamp() ) );
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.