How to compare dates in PHP

php_date_compareHow to actually compare 2 dates in PHP with each other? The question sounds easier than it is.  The first thought that usually comes is the following. We store both dates as strings and compare them.
Preliminary

<?php
$date1 = "2012-1-12";
$date2 = "2011-10-12";

if ($date1 > $date2)
echo "$date1 is newer than $date2";
else
echo "$date1 is older than $date2";
?>

Output:

2012-1-12 is newer than 2011-10-12

At first glance this seems to be a workable solution. But what if the two data is in a different format?

<?php
$date1 = "12-1-12";
$date2 = "2011-10-12";

if ($date1 > $date2)
echo "$date1 is newer than $date2";
else
echo "$date1 is older than $date2";
?>

Output:

12-1-12 is older than 2011-10-12

Now the date in 2012 is declared to be older than the date in 2011, which is of course wrong. However, from PHP’s point of view, this behavior is correct, because […]

How to execute Perl scripts in Notepad++

notepad++_perl_executeA few days ago I already described how to set up the Eclipse development environment for usage with Perl scripts. If you don’t want to use a sledgehammer to crack a nut,  you can also use the Notepad++ editor to relatively comfortably write Perl scripts.
Besides syntax highlighting and intellisense aka auto completion, Notepad++ also offers the possibility to execute Perl scripts directly from the editors interface. However, therefore a one-time setup is necessary, which I want you to briefly explain below.
Step 1 – create test scripts:
perl-skripte_in_npp_ausführen_1  perl-skripte_in_npp_ausführen_2
To be able to check if you have set up everything correctly later, you should definitely first create a small Perl script and save […]

Best of Web #6

best of webNew week, new episode of “Best of Web”. This time I have prepared myself in time, so I could publish the article for this week even before the late evening. One learns to do so.
Today there is again a more “colorful” mix than last week – in other words, not just software topics. Among other things a Turing machine out of LEGO, a few practical tips for SublimeText users and some stuff out of the programmers corner.
I hope you enjoy reading and now I give the “ring-free” for the link tips of the week.
Measure battery lifetime with Windows
That there is available the one or the other useful tool in Windows, which is not found right away, each should be clear about. From the remote assistance solution, up to the “God […]

Best of Web #5

best of webToday the new week started, so there has to be a new article in my “Best of Web” series. Although I reached my selfmade aim (to post an Best of Web article on every monday) again this week, it is, jast as the last few times also, late in the evening. So maybe I should better announce my series as follows: “Best of the Web is a weekly series of articles, which will be, if at all, published in the night from Monday to Tuesday.” Anyway – Monday is Monday and so it goes to the next round.
This week the topics are very software-heavy – which exactly means that all articles, except for two in which the hardware is mentioned, will deal with software and software problems this week. The […]