Knowledgebase

Dates and Times in PHP Print

  • phplaravel, php, woocommerce, guide, howto, solution, zillionkinghost, hosting
  • 0

Temporal values.

WHAT TO USE

The object-based date handling, rather than older function-based approaches.

WHY

It handles time zones, arithmetic and formatting properly.

WHAT TO SET

A default time zone explicitly.

WHY

Relying on the server's setting produces different behaviour in different environments.

WHAT TO STORE

A consistent standard, converting for display.

WHY

Storing local times without zone information produces ambiguity that cannot be resolved later.

WHAT TO BE CAREFUL WITH

Comparing values in different zones Arithmetic across daylight changes, where applicable Parsing text without specifying the format

THE PARSING POINT

Day and month order differs by region.

Specify the expected format rather than allowing interpretation.

WHAT TO USE FOR DIFFERENCES

The interval handling provided, rather than subtracting numbers.

WHAT TO VALIDATE

That parsed dates are plausible.

WHAT LARAVEL ADDS

A richer date library, used throughout the framework.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot