linux OS Quick Tips

Change/update time on Linux

Sets whether the hardware clock is stored as UTC or local time.


Symlink /etc/localtime to /usr/share/zoneinfo/… to set your timezone.

To set the current system date/time.

date MMDDhhmm

To set the hardware clock.

/sbin/hwclock --systohc
Databases MySQL php programming Quick Tips

Getting differences between dates quickly in PHP or MySQL

I recently needed a way to figure out the difference, in days, between two dates. Here is how I did it.

Using PHP:

$expireDate = "2006-02-07";
$year = substr($expireDate, 0, 4);
$month = substr($expireDate, 5, 2);
$day = substr($expireDate, 8, 2);
$splitExpireDate = (mktime(0, 0, 0, $month, $day, $year));
$today = (mktime(0, 0, 0, date("m"), date("d"), date("Y")));
$difference = (($today) - ($splitExpireDate));
$convertToDays = ($difference/86400);
echo $convertToDays;

Using MySQL:

SELECT (TO_DAYS(expire_date) - TO_DAYS(CURDATE())) AS days_expired FROM tablename;
php programming Quick Tips

Get past date or convert different date format with php

Quick way to figure out a past date in PHP.

echo date("Y-m-d", strtotime("20 days ago"));
echo date('Y-m-d',strtotime('12/15/2008'));