Trongate PHP Framework Docs
Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Authorization & Authentication
Tips And Best Practices

Date and Time Fundamentals

Working with dates and times is a common requirement in web applications. Booking systems, event calendars, task managers, scheduling tools - they all need reliable date and time input.

Trongate gives you everything you need with native HTML5 inputs and zero JavaScript.

The Trongate Approach

No custom date pickers. No JavaScript libraries. No complicated configuration.

Just native HTML5 date and time inputs that work everywhere - and framework helpers that make them easy to use.

Why Native HTML5 Inputs?

HTML5 introduced native date and time input types that browsers render with built-in, accessible UI components. Here's why they're the best choice:

  • Zero JavaScript required - the browser handles everything
  • Universal browser support - all modern browsers (Chrome, Firefox, Safari, Edge) fully support these inputs
  • Mobile-optimized - native mobile keyboards and pickers appear automatically
  • Accessible by default - screen readers and keyboard navigation work out of the box
  • Respects user preferences - dates display in the user's locale format automatically
  • Lightweight - no external libraries or CSS frameworks needed
  • Consistent data format - always submits in ISO 8601 format regardless of display

The ISO 8601 Standard

All HTML5 date and time inputs use the ISO 8601 international standard for data interchange. This is crucial for building language-agnostic applications.

Input Type Format Sample Input Value Description
date YYYY-MM-DD 2025-12-27 Calendar date
time HH:MM or HH:MM:SS 14:30 or 14:30:00 Time of day
datetime-local YYYY-MM-DDTHH:MM 2025-12-27T14:30 Date and time (local)
month YYYY-MM 2025-12 Year and month
week YYYY-W## 2025-W52 Year and week number

Key Insight: While the browser may display dates in the user's local format (like "27/12/2025" for UK users or "12/27/2025" for US users), the form always submits in ISO 8601 format. This means your PHP code always receives predictable, consistent data regardless of the user's location.

What Trongate Provides

Trongate gives you simple helpers for every HTML5 date and time input type:

  • - calendar date picker
  • - time selector
  • - combined date and time picker
  • - month and year selector
  • - week selector

Plus validation rules that work seamlessly with ISO 8601 formats:

  • valid_date - validates YYYY-MM-DD format
  • valid_time - validates HH:MM or HH:MM:SS format
  • valid_datetime_local - validates YYYY-MM-DDTHH:MM format
  • valid_month - validates YYYY-MM format
  • valid_week - validates YYYY-W## format

A Simple Example

Here's a complete working form with date and time inputs:

And the view file:

That's it. Clean, simple, and it works everywhere.

Database Storage Strategy

ISO 8601 formats map perfectly to standard SQL date and time types:

HTML5 Input ISO Format MySQL Type Storage Example
date YYYY-MM-DD DATE 2025-12-27
time HH:MM:SS TIME 14:30:00
datetime-local YYYY-MM-DDTHH:MM DATETIME 2025-12-27 14:30:00

Important: When storing datetime-local values in MySQL, you'll need to convert the ISO format (2025-12-27T14:30) to MySQL format (2025-12-27 14:30:00) by replacing the "T" with a space and optionally adding seconds. See the Database Storage Best Practices chapter for details.

Language-Agnostic Design

Trongate's approach to dates and times is intentionally language-agnostic:

  • Store in ISO 8601 - universal standard understood everywhere
  • Database uses standard SQL types - DATE, TIME, DATETIME work in any database
  • Display format is separate - use PHP's DateTime and IntlDateFormatter for locale-specific display
  • Validation checks format - not locale-specific date rules

Example: Multi-Language Date Display

The key principle: store universally, display locally.

Browser Support

All modern browsers fully support HTML5 date and time inputs:

Browser Date Support Time Support DateTime-Local Support
Chrome ✓ Full ✓ Full ✓ Full
Firefox ✓ Full ✓ Full ✓ Full
Safari ✓ Full ✓ Full ✓ Full
Edge ✓ Full ✓ Full ✓ Full
Mobile (iOS/Android) ✓ Full ✓ Full ✓ Full

Legacy Browser Note: Very old browsers (IE 11 and earlier, Safari < 14.1) may render date/time inputs as plain text fields. In these cases, users can still type dates manually in the ISO format, and Trongate's validation will ensure the format is correct.

Timezone Considerations

The datetime-local input type intentionally does not include timezone information. This is by design:

  • It represents a date and time "as displayed on a calendar and wall clock" in the user's local timezone
  • Perfect for scheduling appointments, setting deadlines, booking reservations
  • The server receives the time exactly as the user entered it

Important: If your application requires true timezone-aware timestamps (like "8:00 AM Pacific Time" vs "8:00 AM Eastern Time"), you'll need to capture timezone information separately - either by detecting it with JavaScript, asking the user to select it, or storing it in the user's profile. For most applications, however, datetime-local is exactly what you need.

What's Next

The following pages will show you:

  • How to use each date and time input helper function
  • How to validate date and time data with built-in rules
  • How to handle date ranges and custom validation
  • How to store dates and times in your database
  • How to format dates and times for display in any language
  • How to work with the create/update pattern for date fields

Why This Beats Custom Date Pickers

Custom JavaScript pickers Trongate (Native HTML5)
Require JavaScript libraries (often 50KB+) Zero JavaScript - browser does it all
Break without JavaScript enabled Work everywhere, always
Inconsistent mobile experience Native mobile keyboards and pickers
Accessibility often an afterthought Accessible by default
Return data in various formats Always ISO 8601 - predictable and standard
Require configuration for localization Browser handles display format automatically
Add maintenance burden Maintained by browser vendors

Bottom Line: Native HTML5 date and time inputs are faster, lighter, more accessible, more reliable, and easier to maintain than any JavaScript-based solution. Trongate's helpers make them trivial to use.