Bala
Bala

Reputation: 3638

How to update a timestamp field of a mysql table ?

I want to update all the empty logout_time fields into 2011-12-26 14:48:36.

I tried the following query so as to update the logout_time field (timestamp) in the log_details table:

update log_details set logout_time='2011-12-26 14:48:36',tab_status='0' 
where logout_time =''

It doesn't work. Please help me to fix it.

Upvotes: 4

Views: 14576

Answers (4)

Timur
Timur

Reputation: 6718

update log_details set logout_time='2011-12-26 14:48:36',tab_status='0' 
where logout_time IS NULL

Upvotes: 1

Kokers
Kokers

Reputation: 1828

Check if those "empty" fields are '0000-00-00 00:00:00'. If it's timestamp most likely that would be the case and not "empty" as null empty. The best way is to check what exactly you have in fields you want to update.

//update

if field is actually NULL then it should be

update log_details set logout_time='2011-12-26 14:48:36',tab_status='0' 
where logout_time IS NULL

Upvotes: 1

maxjackie
maxjackie

Reputation: 23282

update log_details set logout_time='2011-12-26 14:48:36',tab_status='0' 

where logout_time ='0000-00-00 00:00:00'

this query should help because the timestamp column empty means '0000-00-00 00:00:00'

Upvotes: 1

aleroot
aleroot

Reputation: 72636

Try with UNIX_TIMESTAMP function in this way :

update log_details set logout_time=UNIX_TIMESTAMP('2011-12-26 14:48:36'),tab_status='0' 
where logout_time =''

Upvotes: 1

Related Questions