Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if date is later than current date [duplicate]

Tags:

date

php

How can I check if the date is later than the current date?

if(date("d") < "18" && date("m") < "01") { 
    echo 'To late!';
}

Doesn't work for me.

like image 577
zerophreak Avatar asked Jan 28 '14 17:01

zerophreak


People also ask

How do you know if a date is greater than another date?

Sample Solution-4: Checks if a date is after another date. Use the greater than operator (>) to check if the first date comes after the second one.

How do you check if a date is greater than another date in JS?

To check if a date is before another date, compare the Date objects, e.g. date1 < date2 . If the comparison returns true , then the first date is before the second, otherwise the first date is equal to or comes after the second.

Does new Date () Return current date?

Use new Date() to generate a new Date object containing the current date and time. This will give you today's date in the format of mm/dd/yyyy.


2 Answers

You can do this notation:

if( '20140505' > date("Ymd") ) {
    // today's date is before 20140505 (May 5, 2014)
}
like image 132
Niels Avatar answered Oct 13 '22 05:10

Niels


$time1  = strtotime(date("d/m/Y", "18/01/2014"));
  if(time() > $time1)
   {
     echo "too late!";
   } 
like image 28
Zakaria.dem Avatar answered Oct 13 '22 07:10

Zakaria.dem