简体   繁体   中英

MYSQL TIMESTAMP comparison

I have a table with a column Time that stores a timestamp value, a column that stores a Name and a column that stores a Status .

I'm trying to find a query to update all entries before a given timestamp like this:

UPDATE `Table` 
SET Status=1
WHERE Name='personname' AND 'Time'<'2012-12-23 18:00:00'

The query is valid but nothing changes.

When trying to show the results of the WHERE part there are no results.

What am I doing wrong?

You're comparing the string literal 'Time' :

'Time'<'2012-12-23 18:00:00'

Try comparing the time column instead:

Time < '2012-12-23 18:00:00'

Or if you have to, surround it in backticks:

`Time` < '2012-12-23 18:00:00'

Live example at SQL Fiddle.

If you are sure about backticks and single quotes and still it doesnt work then try this out,

UPDATE `Table`SET Status=1
WHERE Name='personname' AND 
Time < STR_TO_DATE('2012-12-23 18:00:00','YYYY-MM-DD HH:MI:SS')

Try This:

UPDATE `Table`SET Status=1
WHERE Name='personname' AND 
Time < UNIX_TIMESTAMP(STR_TO_DATE('23-12-2012 18:00:00',' "%d-%m-%Y %h:%i:%s'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM