2014-10-16 185 views
-3

我想獲得已插入到mysql數據庫中的Year,Month值。我試過這個SQL代碼。但它是行不通的從MYSQL獲取月份,年份CURRENT_TIMESTAMP

 $sql = "SELECT EXTRACT(MONTH FROM TIMESTAMP 'paid_time') FROM tbl_pkg_payment_details WHERE client_email='[email protected]'"; 

paid_time是我的Table的時間戳列名。它的確切代碼是什麼?

+0

誰是愚蠢誰給出了這個重要問題的負反饋? – Nadishan 2014-10-16 22:57:12

+0

什麼是時間戳「'pay_time」的列名?你想要月份名稱(1月,2月,...)還是月份編號(1,2,...)? – slapyo 2014-10-16 23:01:11

+0

查看文檔。這些類型的問題的答案通常駐留在那裏。 [嘗試此頁,例如](http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format) – Ohgodwhy 2014-10-16 23:06:57

回答

0

看看MySQL的Date and Time Functions

如果你想月份名稱使用:

$sql = "SELECT MONTHNAME(paid_time) as month, YEAR(paid_time) as year FROM tbl_pkg_payment_details WHERE client_email='[email protected]'"; 

如果你想月份數字使用:

$sql = "SELECT MONTH(paid_time) as month, YEAR(paid_time) as year FROM tbl_pkg_payment_details WHERE client_email='[email protected]'"; 
+0

今年......哪裏? – Ohgodwhy 2014-10-16 23:08:17

+0

在...中添加了它,因此我應該包含它,但它不在提供的查詢中。 – slapyo 2014-10-16 23:10:26