开发者

mysql substr not working like php substring

开发者 https://www.devze.com 2023-01-26 05:56 出处:网络
my date format is like 2010-11-15 04:28:31 i want to pick just 2010-11-15 instead of 2010-11-15 04:28:31 ,

my date format is like

2010-11-15 04:28:31

i want to pick just 2010-11-15 instead of 2010-11-15 04:28:31 ,

using MYSQL query ,

SELECT SUBSTR(my_date,0,6) FROM TB开发者_JAVA技巧L ,

This query retrieving just empty value ,

How to form substr function in mysql QUERY ,


MySQL uses 1-based strings, so the first character is 1, while in php the first character is 0.

Better is to use the DATE function to get the date-part only from a date time field. That is, if your field is indeed a date time field, not a (var)char field.

If you want to display your date in a specific format you can also use

DATE_FORMAT(my_date, '%Y-%m-%d') 
0

精彩评论

暂无评论...
验证码 换一张
取 消