Solved

MySQL GET_FORMAT() not working as expecte

Posted on 2010-08-13
2
392 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query help 15 55
Survey branching tutorial 11 44
MySQL-Design Help 12 44
A responsive image gallery using flexbox 6 23
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 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