PHP code example of codingwithrk / nativephp-datetime-picker

1. Go to this page and download the library: Download codingwithrk/nativephp-datetime-picker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codingwithrk / nativephp-datetime-picker example snippets


use Livewire\Component;
use Native\Mobile\Attributes\OnNative;
use Illuminate\Support\Carbon;
use Codingwithrk\NativephpDatetimePicker\Facades\DateTimePicker;
use Codingwithrk\NativephpDatetimePicker\Events\DateTimePickerConfirmed;
use Codingwithrk\NativephpDatetimePicker\Events\DateTimePickerCancelled;

class BookingForm extends Component
{
    public ?string $startsAt = null;

    public function pickStart(): void
    {
        DateTimePicker::make()
            ->dateTime()
            ->min(now())
            ->max(now()->addMonths(6))
            ->current(now())
            ->title('When does it start?')
            ->use12h()
            ->show();
    }

    #[OnNative(DateTimePickerConfirmed::class)]
    public function onPicked($value, $mode, $timestamp = 0, $id = null): void
    {
        $this->startsAt = Carbon::parse($value)->toDateTimeString();
    }

    #[OnNative(DateTimePickerCancelled::class)]
    public function onCancelled($id = null): void
    {
        //
    }
}

use Codingwithrk\NativephpDatetimePicker\Facades\DateTimePicker;

DateTimePicker::date();            // date only
DateTimePicker::time();            // time, 24-hour
DateTimePicker::time12h();         // time, AM/PM
DateTimePicker::dateTime(now());   // date + time