AthenaeumAthenaeum
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
Packages
  • next
  • current
  • v9.x
  • v8.x
  • v7.x
  • v6.x
  • v5.x
  • v4.x
  • v3.x
  • v2.x
  • v1.x
Changelog
GitHub
  • Version 5.x

    • Release Notes
    • Upgrade Guide
    • New to this...
    • Origin
  • ACL

    • Introduction
    • How to install
    • Setup
    • Permissions
    • Roles
    • Users
    • Cached Permissions
  • Circuits

    • Circuits
    • How to install
    • Setup
    • Usage
    • Events
  • Collections

    • Collections
    • How to install
    • Summation

      • Summation Collection
      • Items Processor
  • Config

    • Configuration Loader
    • How to install
    • Setup
    • Load Configuration Files
    • Custom File Parsers
  • Console

    • Command and Schedule Registration
    • How to install
    • Setup
    • Commands
    • Schedules
  • Container

    • IoC Service Container
    • How to install
    • Container
    • List Resolver
  • Core

    • Athenaeum Core Application
    • Prerequisite
    • How to install
    • Integration
    • Usage

      • Configuration
      • Service Providers
      • Service Container
      • Events
      • Caching
      • Logging
      • Console
      • Task Scheduling
      • Exception Handling
      • Extending Core Application
      • Testing
  • Database

    • Introduction
    • How to install
    • Models

      • Instantiatable
      • Sluggable
    • Query

      • Criteria (Query Filter)
  • Dto

    • Data Transfer Object (DTO)
    • How to install
    • Create Interface
    • Implement DTO
    • How to use
    • Populate
    • Export
    • Json
    • Serialization
    • Nested DTOs
    • Array DTO
  • Events

    • Register Listeners and Subscribers
    • How to install
    • Setup
    • Listeners
    • Subscribers
  • Filters

    • Search Filter Utilities
    • Prerequisites
    • How to install
    • Setup
    • Processor
    • Filters Builder
    • Predefined Resources

      • Search Processor
      • Sorting Processor
      • Constraints Processor
      • Matching Processor
    • Tip: Create a base builder
  • Http

    • Clients

      • Http Clients
      • How to install
      • Setup
      • Basic Usage
      • Available Methods

        • Fluent Api
        • Protocol Version
        • Base Uri
        • Http Method and Uri
        • Headers
        • Accept & Content-Type
        • Authentication
        • Http Query
        • Payload Format
        • Payload
        • Attachments
        • Cookies
        • Response Expectations
        • Middleware
        • Conditions
        • Criteria
        • Redirects
        • Timeout
        • Debugging
        • Logging
        • Driver Options
        • Driver
      • Http Query Builder

        • Introduction
        • Select
        • Where
        • Dates
        • Include
        • Pagination
        • Sorting
        • Raw Expressions
        • Custom Grammar
    • Cookies

      • Http Cookies
      • How to install
      • Usage
    • Messages

      • Http Messages
      • How to install
      • Serializers
  • Properties

    • Properties Overload
    • How to install
    • Usage
    • Naming Convention
    • Properties Visibility
  • Redmine

    • Redmine Api Client
    • How to install
    • Setup
    • General Usage

      • Supported Operations
      • Fetch list of resources
      • Find
      • Fetch
      • Create new record
      • Update existing record
      • Delete existing record
      • Relations
    • Available Resources

      • Predefined Resources
      • Attachments
      • Enumerations
      • Issue Relations
      • Users
      • User Groups
      • Roles
      • Project Memberships
      • Versions (Milestones)
      • Issue Categories
      • Trackers
  • Service

    • Service Registrar
    • How to install
    • How to use
  • Support

    • Introduction
    • How to install
    • Laravel Aware-of Helpers

      • How to use
      • Enforce Via Interface
      • Custom Default
      • Pros and Cons
      • Available Helpers
    • Aware-of Properties

      • Generator
      • Available Aware-of Helpers
    • Live Templates
  • Testing

    • Introduction
    • How to install
    • Test Cases
    • Testing Aware-of Helpers
  • Utils

    • Introduction
    • How to install
    • Array
    • Duration
    • Json
    • Math
    • Method Helper
    • Populatable
    • Version
  • Validation

    • Introduction
    • How to install
    • Setup
    • Rules

      • Alpha-Dash-Dot
You are viewing documentation for an outdated version. It is no longer supported!

Dates

The Http Query builder offers a few methods for adding date-based conditions, in you query string.

  • Formats
  • Arguments
  • Where Datetime
  • Where Date
  • Where Year
  • Where Month
  • Where Day
  • Where Time
  • Or Methods

Formats

Before showing examples of each supported method, you should know that you can change the date and time formats, for each grammar. This can be done in your configs/http-clients.php configuration file, under each grammar profile. The formats are parsed using PHP's DateTime::format() method.

<?php

return [

    // ... previous not shown ...

    'profiles' => [

        'default' => [
            'driver' => \Aedart\Http\Clients\Requests\Query\Grammars\DefaultGrammar::class,
            'options' => [

                /**
                 * Date formats
                 */
                'datetime_format' => \DateTimeInterface::ISO8601,
                'date_format' => 'Y-m-d',
                'year_format' => 'Y',
                'month_format' => 'm',
                'day_format' => 'd',
                'time_format' => 'H:i:s',
            ]
        ],
    ]
];

Arguments

Each of the available date-based condition methods accept the following arguments:

  • $field: string field/filter name
  • $operator: string|DateTimeInterface string operator or value
  • $value: string|DateTimeInterface (optional) date, either as a string or instance that inherits from DateTimeInterface. If omitted, the $operator acts as the value.

If no value is given, then the current datetime (now) is used as the default value.

Where Datetime

The whereDatetime() adds a condition using a full "date & time" format.

$response = $client
        ->whereDatetime('created', '2020-04-05')
        ->get('/users');
default
/users?created=2020-04-05T00:00:00+0000
json api
/users?filter[created]=2020-04-05T00:00:00+0000
odata
/users?$filter=created eq 2020-04-05T00:00:00+0000

Where Date

whereDate() can be used to add a condition where "year, month and day" formats are expected.

$response = $client
        ->whereDate('created', 'gt', new DateTime('now'))
        ->get('/users');
default
/users?created[gt]=2020-04-05
json api
/users?filter[created][gt]=2020-04-05
odata
/users?$filter=created gt 2020-04-05

Where Year

whereYear() adds a date condition, where "year" is used as format.

$response = $client
        ->whereYear('created', 'lt', new DateTime('now'))
        ->get('/users');
default
/users?created[lt]=2020
json api
/users?filter[created][lt]=2020
odata
/users?$filter=created lt 2020

Where Month

whereMonth() adds a condition, where "month" is used as format.

$response = $client
        ->whereMonth('created', '2020-07-15')
        ->get('/users');
default
/users?created=07
json api
/users?filter[created]=07
odata
/users?$filter=created eq 07

Where Day

To add a condition where "day" format is expected, use the whereDay() method.

$response = $client
        ->whereDay('created', 'gt', '2020-07-15')
        ->get('/users');
default
/users?created[gt]=15
json api
/users?filter[created][gt]=15
odata
/users?$filter=created gt 15

Where Time

Conditions based on "time" format, can be added via whereTime().

$response = $client
        ->whereTime('created', 'lt', new DateTime('now'))
        ->get('/users');
default
/users?created[lt]=16:58:00
json api
/users?filter[created][lt]=16:58:00
odata
/users?$filter=created lt 16:58:00

Or Methods

You may also use the orWhereDatetime(), orWhereDate(), orWhereYear()...etc methods to add "or" conjunctions. But, apart from OData, these are NOT considered conventional. For additional information about "or" conjunctions, please read the orWhere() documentation.

Edit page
Last Updated: 26/03/2023, 19:41
Contributors: Alin Eugen Deac
Prev
Where
Next
Include