Tuesday 26 June 2012

Format Date Time using MySQL Query

// The Below Query will select all the users date in (20-06-2012 17:25:36) format while search the list of users records which are created (date_created) in the current month only.

SELECT DATE_FORMAT(date_created, '%d-%m-%Y %H:%i:%s') as initial_date
FROM users 
WHERE (SELECT MONTH(date_created)) = ( SELECT MONTH( NOW() ) ) 

Thursday 7 June 2012

Get the number of words from the string or paragraph

Get Chunk/No of words from the string or paragraphs 
This is similar to substr of the built-in php function.

// Fetch the chunk of string by number of words from the paragraph or string.
function substr_words ($string, $num_words)
{
 $string = explode (' ', $string);
 $string = array_slice ($string, 0, $num_words);
 return implode (' ', $string);
}

Wednesday 6 June 2012

Hours Mins and Seconds difference between two dates.

// Hours Mins and Seconds difference between two dates.
function timeDifference($date1=null, $date2=null)
{
 $date1 = !empty($date1) ? $date1 : date('Y-m-d H:i:s');
 $date2 = !empty($date2) ? $date2 : date('Y-m-d H:i:s');
 
 $dateDiff    = abs(strtotime($date1) - strtotime($date2));
 
    $fullHours   = floor($dateDiff / (60*60) );
    $fullMinutes = floor(($dateDiff-($fullHours*60*60))/60);   
    $fullSeconds = ($dateDiff-($fullHours*60*60)-($fullMinutes*60));
    
    return ('T-'.$fullHours.':'.$fullMinutes.':'.$fullSeconds);
}

To Run Yiic command for Yii Framework in Windows

// To Run Yiic command for Yii Framework in Windows 
Step-1: Go to the php directory where it is installed. e.g. C:\xampp\php
Step-2: Run below command.
             PATH1- Path to the framework folder: C:\xampp\htdocs\YiiMain\framework\yiic.php
             PATH2- Path to the new application folder: C:\xampp\htdocs\newApplicationName
C:\xampp\php>php PATH1 webapp PATH2