Archive for the ‘php’ Category

Php mysql 日期时间处理入门

Wednesday, May 13th, 2009

php日期时间格式是这样的 年-月-日 时:分:秒

$dt = "0000-00-00 00:00:00";

 

 
从mysql取出和输入的datetime也是这样格式。

假设你只要显示比较friendly的日期,我要介绍php里这个很方便的function strtotime

$display = date('D, d M y' , strtotime($dt) )
//输出结果Tues, 12 January 2008 [字串]

 

 
更多关于date函数 可以到php date手册查看

如果要获得现在日期时间

$dt = date();
或者
$dt = date('d-m-y h:i:s');

  

 

需要mysql里一个column专存取当时时间你可以设该column为timestamp
如果你已经设为datetime了也无所谓,sql语句里 insert into `table` (`dt`) value (now())
除了now() mysql还有许多日期时间函数查找手册

举例,要求日期在一时段内的SQL语句

SELECT * FROM `table` WHERE ( opendate_col <= now() ) 
AND (closedate_col >=now() )

php - object to array 对象转数组

Monday, April 27th, 2009
$array = get_object_vars( $object );

notice! only public variable will be converted!

example :

class foo {
private $a;
public $b = 1;
public $c;
private $d;
static $e;
}
$test = new foo;
var_dump(get_object_vars($test));



The above example will output:

array(2) {
["b"]=> int(1)
["c"]=> NULL
}

Copyright © 2010 Elliot Yard. Search Engine Optimization by Star Nine. Distributed by Wordpress Themes