3

Coding with Python, I want to insert time processed on the database side like this:

time = func.now()-datetime.timedelta(days=100)

or

time = func.current_timestamp()-datetime.timedelta(days=100)

but somehow it couldn't get through, seeing warning:

sqlalchemy\engine\default.py:330: Warning: Truncated incorrect DOUBLE value: '1970-01-04 00:00:00'

Any way to get it straight? thanks.

================================

I want to update a TIMESTAMP column 'date_buy' in table 'Purchase', an d instead of using datetime.datetime.now() to get the update time in python, I want to get this done in the database, meaning I would prefer func.now():

time = func.current_timestamp()-datetime.timedelta(days=100)
# time = datetime.datetime.now()-datetime.timedelta(days=100)
session.execute(update(Purchase).values(date_buy=time).where(Purchase.c.id == 11))

=================================

solved. thanks to Bryan and his post: http://groups.google.com/group/sqlalchemy/browse_thread/thread/a67d4f179e01b98a/ee688a0b8a999f52?hl=en&lnk=gst&q=date_add#ee688a0b8a999f52

1
  • If you found the solution then accept the answer to close the question. Please do this to complete the workflow of the system. Commented Feb 9, 2012 at 5:07

1 Answer 1

2

The Warning is

Warning: Truncated incorrect DOUBLE value: '1970-01-04 00:00:00'

Means its truncating your data. Please check your field type in which you are going to store the time object. It says that you are trying to store DOUBLE value with datetime value.

If this will not solve the problem then just give some code example so we will get idea what you are going to do.

Sign up to request clarification or add additional context in comments.

3 Comments

pls take a look at the edited post. i am not sure if this is a right way to leave the operation on that field to MySQL, not python. thanks!
What is the type of date_buy? Please provide the class of Purchase.
CURRENTTIMESTAMP is double value and you are trying to minus datetime from CURRENTTIMESTAMP. Just use same type of operand to perform the operation. You can use converttimestamp(func.now() - datetime.timedelta(days=100))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.