LoginSignup
4
5

More than 5 years have passed since last update.

特定の2つの日付の間から、ランダムに1日を取得

Last updated at Posted at 2017-10-19
// 特定の2つの日付の例
$start = Carbon::create("2015", "1", "1");
$end = Carbon::create("2020", "12", "31");

// タイムスタンプに変換
$min = strtotime($start);
$max = strtotime($end);

// タイムスタンプにした2つの日付の中からランダムに1つタイムスタンプを取得
$date = rand($min, $max);

// タイムスタンプ => Y-m-d に変換    
$date = date('Y-m-d', $date)
4
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5