Solved

MySQL GET_FORMAT() not working as expecte

Posted on 2010-08-13
2
391 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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

856 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