LLMS_Date::get_date_range_by_filter( string $filter )

Get date range by filter


Description Description

Calculates the date range based on the filter value selected.


Top ↑

Parameters Parameters

$filter

(string) (Required)


Top ↑

Return Return

(array) $date_range


Top ↑

Source Source

File: includes/class.llms.date.php

	public static function get_date_range_by_filter( $filter ) {

		$today         = current_time( 'Y-m-d' );
		$current_month = date( 'm', strtotime( $today ) );
		$current_year  = date( 'Y', strtotime( $today ) );

		if ( 'week' === $filter ) {

			$start_date = self::db_date( $today . '- 7 days' );
			$end_date   = self::db_date( $today );

		} elseif ( 'month' === $filter ) {

			$start_date = date( 'Y-m-01', strtotime( $today ) );
			$end_date   = date( 'Y-m-t', strtotime( $today ) );

		} elseif ( 'quarter' === $filter ) {

			if ( $current_month >= 1 && $current_month <= 3 ) {
				$start_date = $current_year . '-01-01';
				$end_date   = $current_year . '-03-31';
			} elseif ( $current_month >= 4 && $current_month <= 6 ) {
				$start_date = $current_year . '-04-01';
				$end_date   = $current_year . '-06-30';
			} elseif ( $current_month >= 7 && $current_month <= 9 ) {
				$start_date = $current_year . '-07-01';
				$end_date   = $current_year . '-09-30';
			} elseif ( $current_month >= 10 && $current_month <= 12 ) {
				$start_date = $current_year . '-10-01';
				$end_date   = ( $current_year + 1 ) . '-01-01';
			}
		} elseif ( 'year' === $filter ) {

			$start_date = $current_year . '-01-01';
			$end_date   = ( $current_year + 1 ) . '-01-01';
		}

		$date_range = array(
			'start_date' => $start_date,
			'end_date'   => $end_date,
		);

		return $date_range;

	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.