?
Solved

MySQL GET_FORMAT() not working as expecte

Posted on 2010-08-13
2
Medium Priority
?
395 Views
Last Modified: 2013-12-13
Hello,

I'm trying to update one datetime field based on other datetime filed that is bigger than 1 day than the other

This is my query:

UPDATE TABLE SET `field`='amyvalue' WHERE datetime_field < GET_FORMAT(UNIX_TIMESTAMP(`other_datetime_field`)-86400, 'ISO')


I'm getting this error:
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNIX_TIMESTAMP(`other_datetime_field`)-86400, 'ISO')' at line 1


How can I use GET_FORMAT() to get it to work properly ?

Thank you
0
Comment
Question by:Ionut A. Tudor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 33427687
what is the data type of datetime_field and other_datetime_field, please?if it's really datetime:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.htmlhttp://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
UPDATE TABLE 
  SET `field`='amyvalue' 
WHERE datetime_field < date_sub(`other_datetime_field`, INTERVAL 1 DAY)

Open in new window

0
 
LVL 14

Author Comment

by:Ionut A. Tudor
ID: 33427762
Yes angelll, I needed it for doing the below and it worked. Thanks

UPDATE orders SET `other_datetime_field`=DATE_SUB(`datetime_field`, INTERVAL 2 DAY) WHERE id='1' LIMIT 1

Open in new window

0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question