473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

parsing a date string

Hi,

I have a date string in the ctime() format ('Sat Mar 5 10:38:07 2005')
and I want to know how long ago that was in whole days.

So far I have:

import time
import datetime
age =
(datetime.date.fromtimestamp(time.mktime(time.strp time(date.strip()))) -
datetime.date.today()).days

Which is an absurd number of function calls and is possibly not even
correct (something in the docs about mktime() taking localtime whereas
my string is in UTC)

Any suggestions?

Thanks
MikeG
Jul 18 '05 #1
1 2201
Am Sun, 06 Mar 2005 19:35:23 +0000 schrieb MikeyG:
Hi,

I have a date string in the ctime() format ('Sat Mar 5 10:38:07 2005')
and I want to know how long ago that was in whole days.

So far I have:

import time
import datetime
age =
(datetime.date.fromtimestamp(time.mktime(time.strp time(date.strip()))) -
datetime.date.today()).days

Which is an absurd number of function calls and is possibly not even
correct (something in the docs about mktime() taking localtime whereas
my string is in UTC)


Try %Z:

time.mktime(time.strptime("Sat Mar 5 10:38:07 2005 UTC",
"%a %b %d %H:%M:%S %Y %Z"))
--> 1110015487.0

time.mktime(time.strptime("Sat Mar 5 10:38:07 2005 CEST",
"%a %b %d %H:%M:%S %Y %Z"))
--> 1110011887.0

HTH,
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
3
by: dont bother | last post by:
Hey, I have been trying to parse emails: But I could not find any examples or snippets of parsing emails in python from the documentation. Google did not help me much too. I am trying to...
9
by: Thomas W | last post by:
I'm developing a web-application where the user sometimes has to enter dates in plain text, allthough a format may be provided to give clues. On the server side this piece of text has to be parsed...
0
by: bj0011 | last post by:
I am trying to parse an XML file obtained from a public WebService (see below). This file does not seem to be loading into a .NET XmlDocument right (I think it is because of all of the <Item Name=""...
50
by: z. f. | last post by:
HI, i have string in format dd/mm/yyyyy hh:mm:ss and giving this as an input to DateTime.Parse gives a string was not recognized as a valid date time format string error. how do i make the parse...
6
by: Tim N. van der Leeuw | last post by:
Hi, I want to parse strings containing date-time, which look like the following: "Mon Dec 19 11:06:12:333 CET 2005" That's a problem for strptime it seems, b/c I cannot find any...
0
by: Uncle Leo | last post by:
I created an OleDbDataAdapter with the wizard in Visual Studio 2003. It created a dataset, connectionstring etc. for me to work with. It also created a .xsd file where one of the columns type is...
2
by: Bit Byte | last post by:
I want to parse a string (actually a date [always in the format 'YYYYMMDD') into integer values like this: void parseDate(const string&sdate, int& day, int& mon, int &year) { istringstream...
10
by: Stu | last post by:
Can somebody please tell me the most effient away to parse the date YYYYMMDD from the following string. char *date_path = "/dira/dirb/dirc/dird/2006/12/04" Note: the number of directories...
3
by: GazK | last post by:
I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. The script has worked well for a couple of years, despite having very crude...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.