2013-01-09 155 views
0

後,我有一個表在我的MySQL數據庫,比如,以下字段:從日期表中選擇行今天

id, client, date

類型是:

id -> int(20) unsigned, client -> varchar(100), date -> varchar(20)

數據例如:

'234', 'John Doe', '08/13'

'112', 'Joanna Doe', '08/12'

我想選擇今天之後的所有記錄爲mm/YY(09/13) 有人可以幫忙嗎?

+0

後各國?你在這裏看到的日子mm/YY '08/12'? –

+0

'date'as varchar(20)?將列類型設置爲日期時間。它會讓你的任務變得輕鬆。 「數據示例」中的' –

+0

':'08/13'和'08/12'(在這種情況下,如果我可以選擇我將只獲得'08/13',因爲今天是'09/13'並且是我所需要的) – bsteo

回答

1
select * 
from yourtable 
where 
    (year(curdate()) % 1000 < substring_index(date, '/', -1)) 
    or 
    (year(curdate()) % 1000 = substring_index(date, '/', -1) 
    and month(curdate()) < substring_index(date, '/', 1)) 
+0

fthiella,謝謝!作爲魅力發揮作用! – bsteo

2

你可以使用MySQL的str_to_date函數。

select * from table where str_to_date(date,'%m/%Y') > sysdate; 

編輯:

實施例:

select date from mytable where str_to_date(date,'%m/%Y') > str_date('01/13','%m/%Y'); 
+0

似乎沒有這樣做:mysql>從'mytable'中選擇'date',其中str_to_date(date,'%m /%Y')> '01/13'限制10; + ------- + |日期| + ------- + | 08/10 | | 10/11 | | 10/13 | | 04/12 | | 07/11 | | 12/11 | | 03/11 | | 05/10 | | 02/12 | | 02/13 | + ------- + 設置10行,1警告(0.00秒) – bsteo

+0

檢查編輯。 –

+0

謝謝jack_carver,編輯工作也! :) – bsteo

相關問題