0

i have two value date 2019-07-30 as startdate and 2019-07-31 as enddate. 2019-07-30 more is date now. and this my code :

$start_date = "2019-07-30";
$end_date = "2019-07-31";

$date_now = timetodate(DT_TIME, 3); //2019-07-30

if(($date_now >= $start_date) && ($date_now <= $end_date)){
    echo "promo active!";
}

and how i display promo active even though startdate bigger equal to date_now (30 >= 30)

ogebman
  • 67
  • 7
  • 1
    Possible duplicate of [PHP strtotime date difference](https://stackoverflow.com/questions/25026602/php-strtotime-date-difference) – sancoLgates Jul 29 '19 at 04:27

1 Answers1

2

You need to use strtotime()

<?php

$start_date = "2019-07-29";
$end_date = "2019-07-31";

$date_now = date('Y-m-d');

if((strtotime($date_now) >= strtotime($start_date)) && (strtotime($date_now) <= strtotime($end_date))){
    echo "promo active!";
}

Output:- https://3v4l.org/cX5ed

Note:- I have changed start date to 29 to show you how it will work. (as today is 29 july 2019)

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98