Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'parser': 0.07; 'pypi': 0.07; 'accuracy.': 0.09; 'fails.': 0.09; "person's": 0.09; 'thrown': 0.09; 'formats.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'subject:dates': 0.16; 'wrote:': 0.17; 'example.': 0.17; 'handles': 0.18; 'module': 0.19; 'earlier': 0.21; 'for?': 0.23; "i've": 0.23; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'common': 0.26; 'topic': 0.27; 'question': 0.27; 'code': 0.31; 'url:python': 0.32; 'could': 0.32; 'curious': 0.33; 'handle': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'entered': 0.34; 'formats': 0.35; 'pm,': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'message- id:@gmail.com': 0.36; 'operating': 0.36; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'called': 0.39; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'different': 0.63; 'computers': 0.69; 'american': 0.73; 'url:lang': 0.84; 'url:topic': 0.84; 'task,': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Mon, 10 Dec 2012 22:34:31 -0700 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.11) Gecko/20121115 Thunderbird/10.0.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: strptime - dates formatted differently on different computers References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355204085 news.xs4all.nl 6848 [2001:888:2000:d::a6]:40479 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:34596 On 12/10/2012 02:18 PM, noydb wrote: > Follow-on question to this earlier topic - https://groups.google.com/d/topic/comp.lang.python/wnUlPBBNah8/discussion > > Was curious to know if there was a way to handle different user computers with different operating system set date formats. 2/10/2006 vs 2-10-2006, for example. Not an issue for my current task, but was just curious how this could be handled? > > If in my code I am declaring the user entered date foramtted as > x = datetime.datetime.strptime(user_entered_time , "%m/%d/%Y %I:%M:%S %p") # format for my computer > > but on another person's computer, their's is set as 2-10-2006 14:26:06, the code fails. Can this be accounted for? I use a module I got from pypi called dateutil. It has a nice submodule called parser that can handle a variety of date formats with good accuracy. Not sure how it works, but it handles all the common American date formats I've thrown at it.