国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

phpmysql 日期操作小記

2024-05-04 23:15:32
字體:
來源:轉載
供稿:網友
在時間比較查詢的時候,int的效率明顯更高。祥文見
但是在做項目的時候或者直接在數據庫查看數據的時候,明顯這個int一看頭就大,比如我們想
要查看一個用戶的注冊時間:
select reg_time from t_xx_users where user_id=1;
這時候返回是個int值,不能直觀的看到具體的時間,所以這時候就涉及到datetime和int的轉化問題,
還有php的date和time也是要涉及到相應的轉化。本文略總結一下:
(1)php
int值:
time():是返回自從 Unix 紀元(格林威治時間 1970 年 1 月 1 日 00:00:00)到當前時間的秒數。
我們想要獲得1970 年 1 月 1 日到 2012-2-10的秒數可以通過strtotime()來實現:即:strtotime('2012-2-10');
date值:
string date ( string format [, int timestamp] )
比如:直接date()返回的的實現當前的時間,當然我們可以指定的他的格式:例如date('Y-m-d',strtotime('2012-2-10'));
時間操作:
date('Y-m-d h:i:s',strtotime('+1 week'));
date('Y-m-d h:i:s',strtotime('+5 hours'));
date('Y-m-d h:i:s',strtotime('next Monday));
date('Y-m-d h:i:s',strtotime('last Sunday'));
date('Y-m-d h:i:s',strtotime('+ 1 day',12313223));!!詳見 int strtotime ( string time [, int now] )

(2)mysql
int->datetime
select from_unixtime(int_time) from table;
datetime->int;
select unix_timestamp(date_time) from table;
時間操作:
select dayofweek('2012-2-2');返回一個星期的第幾天
select dayofmonth('2012-2-2');返回一月中的第幾天
select dayofyear('2012-2-2');返回一年中的第幾天
類似函數: month() day() hour() week()......
+幾天 date_add(date,interval 2 days);
-幾天 date_sub(date,interval 2 days);
時間格式:
date_format(date,format)
select DATE_FORMAT('1997-10-04 22:23:00','%W %M %Y');
其他函數:TIME_TO_SEC() SEC_TO_TIME()...
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洛川县| 玉环县| 阿坝县| 上林县| 中西区| 大丰市| 澄江县| 漳平市| 莎车县| 庆元县| 长丰县| 辉南县| 华宁县| 舞阳县| 江阴市| 疏勒县| 万年县| 西乌珠穆沁旗| 馆陶县| 泾源县| 茂名市| 平利县| 栾川县| 周至县| 库尔勒市| 金溪县| 平远县| 勃利县| 乾安县| 方山县| 桃园市| 昌宁县| 昆山市| 吉隆县| 安阳县| 南华县| 读书| 石棉县| 重庆市| 西贡区| 惠水县|