MYSQL - 以不同格式存储的日期dd-mm-yy - 无法检索值

时间:2018-04-23 10:41:28

标签: mysql

我有一个包含以下值的表格。

enter image description here

正如您在图片中看到的那样,日期并未以标准的mysql日期格式存储。

存储在dd-mm-yy

我想在20-09-2017之前选择invoicedate所在的行,因此它应包含第13-09-17行。

我尝试了以下查询,但它没有任何内容。

SELECT * 
FROM `invoices` 
WHERE date_format(invoicedate,'%d-%m-%Y') < date_format(20-09-17,'%d-%m-%Y')

4 个答案:

答案 0 :(得分:1)

使用2017作为日期中的年份,并将日期包装在撇号中:

SELECT * 
FROM `invoices` 
WHERE date_format(invoicedate,'%d-%m-%Y') < date_format('20-09-2017','%d-%m-%Y');

答案 1 :(得分:1)

在我这边date_format('20-09-2017','%d-%m-%Y')的结果为空,这可能是你的理由。

尝试下面的内容(它在我身边很好用):

SELECT * 
FROM `invoices` 
WHERE invoicedate < STR_TO_DATE('20-09-2017', '%d-%m-%Y');

答案 2 :(得分:1)

    SELECT * 
FROM `invoices` 
WHERE strtotime(invoicedate) < strtotime(20-09-17)

答案 3 :(得分:0)

SELECT * 来自color_dict = {0: (0, 255, 255), 1: (255, 255, 0), ....} def rgb_to_onehot(rgb_arr, color_dict): num_classes = len(color_dict) shape = rgb_arr.shape[:2]+(num_classes,) arr = np.zeros( shape, dtype=np.int8 ) for i, cls in enumerate(color_dict): arr[:,:,i] = np.all(rgb_arr.reshape( (-1,3) ) == color_dict[i], axis=1).reshape(shape[:2]) return arr def onehot_to_rgb(onehot, color_dict): single_layer = np.argmax(onehot, axis=-1) output = np.zeros( onehot.shape[:2]+(3,) ) for k in color_dict.keys(): output[single_layer==k] = color_dict[k] return np.uint8(output) STR_TO_DATE(发票,&#39;%d-%m-%Y&#39;)&lt; STR_TO_DATE(&#39; 20-09-2017&#39;,&#39;%d-%m-%Y&#39;) 限制0,30