mysql语句中把string类型字段转datetime类型

mysql语句中把string类型字段转datetime类型
 
在mysql里面利用str_to_date()把字符串转换为日期
 
此处以表h_hotelcontext的Start_time和End_time字段为例,查询当前
时间在此范围之内的数据。  www.2cto.com  
 
select * from h_hotelcontext where now() between STR_TO_DATE
(Start_time,'%Y-%m-%d %H:%i:%s') and STR_TO_DATE(End_time,'%Y-%m-%d %H:%i:%s'); 
 
注:'%Y-%m-%d %H:%i:%s'格式为:2012-10-11 16:42:30
原文地址:https://www.cnblogs.com/reynold-lei/p/3149226.html