question about timestamp and MySQLdb

S

Sean Berry

I am using MySQLdb to connect to a database and retrieve a timestamp from a
table. The problem is I want the timestamp as a long, unformatted and all.

In the table I have a timestamp like this
20051019111617

But, when I retrieve the value and print it I get
2005-10-19 11:16:17

I want the numeric version, not the converted date. Any suggestions?
 
R

Ron Garret

"Sean Berry said:
I am using MySQLdb to connect to a database and retrieve a timestamp from a
table. The problem is I want the timestamp as a long, unformatted and all.

In the table I have a timestamp like this
20051019111617

But, when I retrieve the value and print it I get
2005-10-19 11:16:17

I want the numeric version, not the converted date. Any suggestions?

Two suggestions:

1. Read up on strftime.

2. Rethink what you're doing because it's almost certainly wrong.

rg
 
M

Micah Elliott

I am using MySQLdb to connect to a database and retrieve a timestamp
from a table. The problem is I want the timestamp as a long,
unformatted and all.

In the table I have a timestamp like this
20051019111617

But, when I retrieve the value and print it I get
2005-10-19 11:16:17

I want the numeric version, not the converted date. Any suggestions?

Without giving any thought to MySQLdb or datetime, the simplest thing
that comes to mind is
'20051019111617'
 
D

Dennis Lee Bieber

I am using MySQLdb to connect to a database and retrieve a timestamp from a
table. The problem is I want the timestamp as a long, unformatted and all.

In the table I have a timestamp like this
20051019111617

Do you?
But, when I retrieve the value and print it I get
2005-10-19 11:16:17
And that IS the format MySQL returns timestamp fields in its own
clients. UNLESS you perform an arithmetic operation on the field...

SELECT t.id, t.atime, t.aTime + 0 FROM times t

id atime t.aTime + 0
1 2005-10-19 23:04:40 20051019230440
2 2005-10-19 23:04:44 20051019230444
3 2005-10-19 23:04:44 20051019230444
4 2005-10-19 23:05:58 20051019230558
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

MySQLdb Help 0
a question about mysqldb 3
SqlAlchemy&Pymssql and Insert TimeStamp 0
MySQLdb 2
multi-result set MySQLdb queries. 0
mysqldb - parameter issue 0
MySQLdb and MySQL stored functions 2
MySQLdb and bits 2

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top