Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34570

Re: strptime - dates formatted differently on different computers

Path csiph.com!usenet.pasdenom.info!goblin3!goblin.stu.neva.ru!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.054
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; 'conventions.': 0.09; 'fails.': 0.09; "person's": 0.09; 'posting.': 0.09; 'cc:addr :python-list': 0.10; 'thread': 0.11; 'advice,': 0.16; 'doing,': 0.16; 'failure?': 0.16; 'formats.': 0.16; 'motherboard': 0.16; 'subject:dates': 0.16; 'thread.': 0.16; 'wrote:': 0.17; 'detect': 0.17; 'example.': 0.17; 'accepting': 0.18; 'input': 0.18; '(or': 0.18; 'define': 0.20; 'earlier': 0.21; 'cc:2**0': 0.23; 'for?': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'environment.': 0.27; 'first,': 0.27; 'topic': 0.27; 'question': 0.27; 'code': 0.31; 'url:python': 0.32; 'could': 0.32; 'curious': 0.33; 'environment,': 0.33; 'month,': 0.33; 'handle': 0.33; 'another': 0.33; "can't": 0.34; 'entered': 0.34; 'pm,': 0.35; 'there': 0.35; 'list.': 0.35; 'but': 0.36; 'operating': 0.36; '(for': 0.37; 'previous': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'think': 0.40; 'your': 0.60; 'day,': 0.60; 'save': 0.61; 'day.': 0.63; 'different': 0.63; 'show': 0.63; 'subject': 0.66; 'header:Reply- To:1': 0.68; 'computers': 0.69; 'user,': 0.69; 'internet': 0.71; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'received:74.208.4.194': 0.84; 'url:lang': 0.84; 'url:topic': 0.84; 'sensibly': 0.91; 'task,': 0.91; 'regions': 0.93; 'yours.': 0.93
Date Mon, 10 Dec 2012 16:36:37 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
To noydb <jenn.duerr@gmail.com>
Subject Re: strptime - dates formatted differently on different computers
References <d564ab7b-9259-4460-813a-10a41e0fcd64@googlegroups.com>
In-Reply-To <d564ab7b-9259-4460-813a-10a41e0fcd64@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:RkYT2x9fjeW+qg3smTGd8JPLF9NwcAWjHF7J6TS/vM2 0sxy6z2XKzo96sR52HtZeanp2Yjf7xady7bK4OTzL5NcqSOUT3 MmjDxLIcMIoynOxjWvEHkgUigkfoniEnvb7n+TqJYOTrHFFin+ ZddyAYDndkrhiZAQcJJ0M19do+cnWdcv4gtqQHs6UeeT3L2ZWr SYijbNCS4r3fLdtUC6WCeqkqZTweeZWGiqpWy05MrQ/EZKOeHf InKQ1LMCR3RvkfOkjmGyz36zcWi32LcbUDQW+AdZqr+9BPMx/1 7iDb2eVBoMOCqbza/b1mPKVOYyIiXmkLd5sySwHYnzFGE9gDQ= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.685.1355175418.29569.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355175418 news.xs4all.nl 6943 [2001:888:2000:d::a6]:43009
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34570

Show key headers only | View raw


On 12/10/2012 04:18 PM, noydb wrote:
> Follow-on question to this earlier topic - https://groups.google.com/d/topic/comp.lang.python/wnUlPBBNah8/discussion 

For those who avoid googlegroups with a passion, and/or don't have
internet access, the subject of that thread is "date-time comparison,
aware vs naive", on this same mailing list.

> 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.

You can save people a lot of time if you just think before posting. 
What do you define as failure?  is your motherboard smoking, or is the
final result off by a second?
Please reread my last message on the previous thread.  If you want us to
give you code advice, show us what you're doing, don't just describe it
in vague terms.

>  Can this be accounted for?

When accepting input from a user, consider their environment.  Perhaps
they're in a different timezone than your program (or your native
location), or use some other ordering for the date (for example, the
Japanese sensibly put year first, then month, then day.  Other regions
have different conventions.  If you can't detect the user environment,
then you'd better tell them yours.  For example,by prompting for day,
month, and year separately.


-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

strptime - dates formatted differently on different computers noydb <jenn.duerr@gmail.com> - 2012-12-10 13:18 -0800
  Re: strptime - dates formatted differently on different computers noydb <jenn.duerr@gmail.com> - 2012-12-10 13:22 -0800
  Re: strptime - dates formatted differently on different computers Dave Angel <d@davea.name> - 2012-12-10 16:36 -0500
    Re: strptime - dates formatted differently on different computers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-11 02:07 +0000
  Re: strptime - dates formatted differently on different computers Michael Torrie <torriem@gmail.com> - 2012-12-10 22:34 -0700
  Re: strptime - dates formatted differently on different computers Chris Angelico <rosuav@gmail.com> - 2012-12-11 19:08 +1100
  Re: strptime - dates formatted differently on different computers Michael Torrie <torriem@gmail.com> - 2012-12-11 01:23 -0700
  Re: strptime - dates formatted differently on different computers Michael Torrie <torriem@gmail.com> - 2012-12-11 01:25 -0700
  Re: strptime - dates formatted differently on different computers Chris Angelico <rosuav@gmail.com> - 2012-12-11 19:32 +1100
  Re: strptime - dates formatted differently on different computers Greg Donald <gdonald@gmail.com> - 2012-12-11 02:35 -0600
    Re: strptime - dates formatted differently on different computers noydb <jenn.duerr@gmail.com> - 2012-12-11 06:52 -0800
    Re: strptime - dates formatted differently on different computers noydb <jenn.duerr@gmail.com> - 2012-12-11 06:52 -0800
    Re: strptime - dates formatted differently on different computers Marc Christiansen <usenet@solar-empire.de> - 2012-12-11 21:18 +0100
      Re: strptime - dates formatted differently on different computers Greg Donald <gdonald@gmail.com> - 2012-12-11 23:28 -0600
    Re: strptime - dates formatted differently on different computers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-12 05:05 +0000
      Re: strptime - dates formatted differently on different computers Greg Donald <gdonald@gmail.com> - 2012-12-11 23:29 -0600

csiph-web