1

I a using PHP and would like the date of third day before the script is called in the format of YYYYMMDD. How can I do this?

user3766332
  • 319
  • 1
  • 5
  • 17

4 Answers4

5

Try this

$result = date('Y.m.d',strtotime("-3 days"));
rack_nilesh
  • 553
  • 5
  • 18
2

Use DateTime:

$date = new \DateTime('-3 days');
echo $date->format('Ymd');

// Alternatively, store the string in a variable
$result = $date->format('Ymd');
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
2

try this easy way

echo date('Ymd', strtotime("-3 days"));
Satish Sharma
  • 9,547
  • 6
  • 29
  • 51
0

Atleast visit php.net once before such questions

<?php 
    $date  = mktime(0, 0, 0, date("m")  , date("d")-3, date("Y"));
    echo date('Ymd', strtotime($date));
    ?>
Veerendra
  • 2,562
  • 2
  • 22
  • 39