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 two strings were compared […]

iPhone 5s giveaway – Win 1 of 10 new iPhone 5s

iPhone 5s zu verschenkenAmong the first 1000 commenters here on the blog, I will give away 10 brand-new iPhone 5S *. To enter the contest you have only two thing to do. Write a comment below this article and like my Facebook page. In the next hours I also will post two more tasks on Facebook which will raise your chance to win one of the iPhones. The first task will be: “Like this, if you ever had a cold.” and finally the second upcoming task will be a survey with the following question: “If you are a men, like this – if you are a woman share this”. And always stay tuned because next month I will give away even 100 MacBook Pros*. And so it goes with the social media, am I right?
Now let’s […]

RadioduinoWRT – a do it yourself webradio

RadioduinoWRTToday I want to present you one of my larger craft projects. This time it is not just about software, but also about the associated hardware. What is it? A web radio!
I like to listen to internet radio stations, but I didn’t want to run my pc only for listening to webradios.  Connecting my phone to my stereo either wasn’t a solution, since I’d rather wear this with me, because I don’t want to run for each SMS / Whatsapp message to the music system. And because I always like to tinker, it was obvious to build a web radio as a standalone device myself.
As this article has become a bit longer, there is a brief overview of the following sections of the article, so that everyone can quickly find what he looks for.

What is the RadioduinoWRT?
Considerations before building
What […]

How to create articles on Blogspot with C#

Blogger C# API LogoToday I want to show you how to create a blog article on Blogger.com/Blogspot.com with C#. For this you need first of all the Google.GData.Client.dll, which you can find inside the Google .Net API package.
You can download the API package here from Google. (The file is called Google_Data_API_Setup_2.2.0.msi (Please note that the version number – 2.2.0 – over time may change of course.)
If the download is complete, install the package, open a new project in Visual Studio and add a reference to the Google.GData.Client.dll.
The .dll file can be found in the installation directory of the API package. (Click on the link “add a reference” above, if you need help embedding .dlls into a Visual Studio project.)
If you have included the DLL, you can start already. Blog posts (aka articles) can be created as follows:

private static int […]

How to install Ubuntu on Samsung Galaxy S2

Android Ubuntu ScreenshotToday there is again an article on Android. More specifically, it’s about how you can run Android and Ubuntu (Linux) in parallel on your smartphone or tablet. Although I had already blogged about it before, but today I want to explain the whole setup process, step-by-step (using a slightly different method).
The title of this article is actually not quite correct, because we will not install Ubuntu, but setup some kind of a live system – so we get down to business.
I used my Galaxy S2 for the project. If it works with other smartphones, I could not test, but would be happy about comments on your part, if you tried it.
 
For our purposes we need the following things / conditions:

Android based device with root rights
Android Terminal Emulator (freely available on Google Playstore)
android-vnc-viewer (freely available on […]