By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

question about timestamp and MySQLdb

P: n/a
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?
Oct 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <bew5f.2828$UF4.1651@fed1read02>,
"Sean Berry" <se**@buildingonline.com> wrote:
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
Oct 19 '05 #2

P: n/a
On Oct 19, Sean Berry wrote:
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
import re
re.sub('( |-|:)', '', ' 2005-10-19 11:16:17')

'20051019111617'

--
_ _ ___
|V|icah |- lliott http://micah.elliott.name md*@micah.elliott.name
" " """
Oct 19 '05 #3

P: n/a
On Wed, 19 Oct 2005 11:27:24 -0700, "Sean Berry"
<se**@buildingonline.com> declaimed the following in comp.lang.python:
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
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Oct 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.