Domain Empire

Comparing dates British style

Spaceship Spaceship
Watch
Hey everyone!

This problem has been baffling me all day today.

I am trying to compare dates which are in the British format to see if they are bigger and/or smaller than todays date.

This is what I am using:

PHP:
if($start <= date("d/m/Y") && $end >= date("d/m/Y")){
bla;
}

What this should do is compare and see if todays date falls between the $start and $end

Where am I going wrong?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
The date function returns a formatted string. For the purpose of comparison I would use Unix timestamps (numbers) for example.

There are several functions that can help you achieve the intended purpose...
PHP: DateTime::diff - Manual
PHP: mktime - Manual
 
0
•••
0
•••

TBH sdsinc response is what the OP should follow. The problem with strtotime is that it sometimes has to guess on the possible expected outcome.

As the format is known it is a simple task for the op to change the time into a unix timestamp. If you use strtotime you may end up with unexpected results.
 
0
•••
So what do you recommend peter?
 
0
•••
How do you assign the $start & $end variables ?
 
0
•••
Hey everyone!

Where am I going wrong?
Trying to program when you don't know how!

Read, than re-read the documentation for time & date PHP functions .
Try a few little examples. When you are comfortable with them, then and only then, try using them in a larger program.
 
Last edited:
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back