date Date and time related processing for Yii framework

  1. Requirements
  2. Installation
  3. Usage
  4. Resources

Date and time related processing for Yii framework, has several useful methods to deal with date and datetime strings, also for formatting date and datetime values to be database compatible.

Requirements

The component is build for Yii framework version 1.1 or above, no other specific requirements.

Installation

Download the extension here or from the Github repo, extract the files to their appropriate folders.
Place this code within your configuration file (main.php) inside the 'components' section

'Date' => array(
     'class'=>'application.components.Date',
     //And integer that holds the offset of hours from GMT e.g. 4 for GMT +4
     'offset' => 4,
),

Usage

A controller to illustrate the usage of the component

class DateController extends Controller
{

	/**
	 * Illustrates the usage of Date component
	 *
	 */
	public function actionIndex(){
		//a sample date
		$date = '24-01-2013';
	
		//Returns current datetime formatted for MySQL with the timezone offset applied to it
		echo Yii::app()->Date->now();
		
		//Returns current datetime formatted for MySQL without the timezone offset applied to it
		echo Yii::app()->Date->now(false);
		
		
		//Formats almost any date string or timestamp to a MySQL compatible datetime string with the timezone offset applied to it
		echo Yii::app()->Date->toMYSQL($date);
		
		//Formats almost any date string or timestamp to a MySQL compatible datetime string without the timezone offset applied to it
		echo Yii::app()->Date->toMYSQL($date, false);
		
		
		//Returns the timestamp of current date in seconds with the timezone offset applied to it
		echo Yii::app()->Date->timestamp();
		
		//Returns the timestamp of current date in seconds without the timezone offset applied to it
		echo Yii::app()->Date->timestamp(false);
		
		
		//Returns a datetime string to add to database as default for datetime columns
		echo Yii::app()->Date->nullDateTime();
		
		
		////Returns a date string to add to database as default for date columns
		echo Yii::app()->Date->nullDate();
		
		
		//Given start and end dates in almost any format claculates the number of days within the interval
		echo Yii::app()->Date->daysCount('10-02-2013', '24-01-2013');
		
		
		//Given a year or a date string returns the number of days that the year contains (365 or 366)
		echo Yii::app()->Date->daysInYear($yearOrDate);
		
		
		//stop the execution
		Yii::app()->end();
	}
}

Resources

Additional resources for this extension

6 0
12 followers
733 downloads
Yii Version: 1.1
License: MIT
Category: Date and Time
Developed by: STDev
Created on: Jan 24, 2013
Last updated: 5 years ago

Downloads

show all

Related Extensions