0

Let's assume a 64 bit version of PHP in case that matters

I'm thinking about generating a random datetime but I realised I don't know how far back in time or how far forward in time the min-max possible values for datetime are to use as min-max for random

arcanine
  • 1,933
  • 1
  • 15
  • 22

1 Answers1

0
<?php

$min = \date_create('@' . PHP_INT_MIN);
var_dump($min->format('Y-m-d H:i:s'));

$max = \date_create('@' . PHP_INT_MAX);
var_dump($max->format('Y-m-d H:i:s'));

$diff = \date_diff($min, $max);

echo $diff->format("%R%a days");

https://3v4l.org/8N17M

This is the earliest and furthest datetime I've found so far

Not sure why I'm getting 0 days in the diff though

arcanine
  • 1,933
  • 1
  • 15
  • 22
  • The difference between PHP_INT_MAX and PHP_INT_MIN is greater than PHP_INT_MAX. That may be why you're getting 0 days – Don't Panic Mar 15 '19 at 22:04