Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'example:': 0.03; 'else:': 0.03; 'charset:iso-8859-7': 0.04; 'detect': 0.07; 'diff': 0.07; 'string': 0.09; 'alter': 0.09; 'skip:% 20': 0.09; 'sure)': 0.09; 'wrong,': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; 'from:addr:andy': 0.16; 'simple.': 0.16; 'substituted': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'properly': 0.19; 'entered': 0.20; 'thanks.': 0.20; 'seems': 0.21; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'skip:+ 40': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'correct': 0.29; 'skip:p 30': 0.29; "doesn't": 0.30; '8bit%:3': 0.30; 'start,': 0.30; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'another': 0.32; 'url:python': 0.33; 'skip:d 20': 0.34; "i'd": 0.34; 'something': 0.35; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'format.': 0.36; 'joined': 0.36; 'url:listinfo': 0.36; 'possible': 0.36; 'url:org': 0.36; 'should': 0.36; 'list': 0.37; 'clear': 0.37; '8bit%:4': 0.38; 'ability': 0.39; 'skip:& 20': 0.39; 'itself': 0.39; 'sure': 0.39; 'mailing': 0.39; 'skip:p 20': 0.39; 'url:mail': 0.40; 'how': 0.40; 'even': 0.60; 'manually': 0.60; 'matter': 0.61; 'to:addr:gmail.com': 0.65; 'winter': 0.68; 'saving': 0.69; 'soon.': 0.71; 'hey,': 0.75; 'greece': 0.84; 'greek': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=a4yGVx7KwxmNcSwU2G9kQfDGomFM/ncn+mwIjpcqXi0=; b=gCptv1gTsUZizv4DqWH+Qa5QIs4S6r/dgaD42OFG+gCCK1CPYGGpC0WvfCt+TxW3WH PJ0cw3T9rb36KD46e/DUGzIugDDB0p6ftZK2uomylbl8SeW+WYWmMHrEPRnCzz+/UrFl +yD/5rMuzw6wn9VQJvzgy9Bv52UGRw5XuQmRmLO5B+k5VgjVYstNCZAzOIxnEC3F/Tiw YDA8K5gXujqYuAYqsTGg4s+MoiwFwCYvWUthx1Xa+rN93jgC8jSCz554ENSz9phTit3q QDPIBvX8Gwdt9tk0P6ltYo6EoxYZV5UN5eVRMBdJCgyGibkfq22LNpCMCM0ksjyRLHk+ qkww== X-Received: by 10.194.21.225 with SMTP id y1mr1040368wje.60.1384260498840; Tue, 12 Nov 2013 04:48:18 -0800 (PST) MIME-Version: 1.0 Sender: vtxvtx@gmail.com In-Reply-To: References: From: Andy Lawton Date: Tue, 12 Nov 2013 12:47:58 +0000 X-Google-Sender-Auth: LLpyoaa4srpltuUubhez_WKDjDw Subject: Re: datetime question To: Ferrous Cranus Content-Type: multipart/alternative; boundary=047d7b5d98ab4f63d504eafa43aa Cc: python-list@python.org 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: 159 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1384260501 news.xs4all.nl 15946 [2001:888:2000:d::a6]:43232 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:59189 --047d7b5d98ab4f63d504eafa43aa Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable Firstly , I should clarify I have no idea how to program python, I joined this mailing list in anticipation of learning soon. And thought I'd have a go playing around with your code and code given to you (worst possible place to start, I'm sure) But from the answers already given to you, this seems to work and as you requested, in reality, this keeps your code to 1 line... I'm sure this is wrong, and isn't what you want, but hey, Correct working code doesn't seem to matter to you anyway... (I think "Europe/Kiev" is Greece but I don't know) from datetime import datetime, time, timedelta import time import pytz def is_dst(zonename): tz =3D pytz.timezone(zonename) now =3D pytz.utc.localize(datetime.utcnow()) return now.astimezone(tz).dst() !=3D timedelta(0) def dst_greece(): if is_dst("Europe/Kiev") : diff =3D 2 else: diff =3D 3 return diff lastvisit =3D (datetime.utcnow() +timedelta(hours=3Ddst_greece())).strftime= ( '%y-%m-%d %H:%M:%S' ) On 12 November 2013 10:15, Ferrous Cranus wrote: > =D3=F4=E9=F2 8/11/2013 11:11 =EC=EC, =EF/=E7 =CD=DF=EA=EF=F2 =C1=EB=E5=EE= =FC=F0=EF=F5=EB=EF=F2 =DD=E3=F1=E1=F8=E5: > >> Is there someway to write the following line even better with the >> >> ability to detect daylight saving time by itself so i don't have to >> alter the line manually when time changes? >> >> lastvisit =3D ( datetime.utcnow() + timedelta(hours=3D2) ).strftime( >> '%y-%m-%d %H:%M:%S' ) # MySQL datetime format >> >> Thanks. >> > > > Example: > > #check if date entered as intented, format it properly for MySQL > lastvisit =3D datetime.strptime(lastvisit, '%d %m %Y').strftime('%Y-%m-%d= ') > > The above code gets the datetime string in a specific way and then conver= t > it to another format. All happens in one line clear and simple. > > Now, in the following statement there shopuld be some way to check for > daylight saving time so i would aboiut add +2 in winter or +3 for greek > summer time. > > > lastvisit =3D ( datetime.utcnow() + timedelta(hours=3D2) ).strftime( '%y-= %m-%d > %H:%M:%S' ) # MySQL datetime format > > I think + timedelta(hours=3D2) should be substituted with something else = but > i don't with what. > -- > https://mail.python.org/mailman/listinfo/python-list > --047d7b5d98ab4f63d504eafa43aa Content-Type: text/html; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable
Firstly , I should clarify I have no idea how t= o program python, I joined this mailing list in anticipation of learning so= on. And thought=A0I'd=A0have a go playing around with your code and cod= e given to you (worst possible place to start, I'm sure)

But from the answers already given to= you, this seems to work and as you requested, in reality, this keeps your = code to 1 line...

I'm sure thi= s is wrong, and isn't what you want, but hey, Correct working code does= n't=A0seem to matter to you anyway...

(I think "Europe/Kiev" is=A0Greec= e=A0but=A0I=A0don't=A0know)

from datetime impo= rt datetime, time, timedelta
import time
import pytz

def is_dst(zonename):
=A0 =A0 tz =3D pytz.time= zone(zonename)
=A0 =A0 now =3D pytz.utc.localize(datetime.utcnow(= ))
=A0 =A0 return now.astimezone(tz).dst() !=3D timedelta(0)

def dst_greece():
=A0 =A0 if is_dst("Europe/Kiev")= :
=A0 =A0 =A0 =A0 diff =3D 2
=A0 =A0 else:
= =A0 =A0 =A0 =A0 diff =3D 3=A0
=A0 =A0 return diff

<= /div>
lastvisit =3D (datetime.utcnow() +timedelta(hours=3Ddst_greece())= ).strftime( '%y-%m-%d %H:%M:%S' )=A0


On 12 N= ovember 2013 10:15, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
=D3=F4=E9=F2 8/11/2013 11:= 11 =EC=EC, =EF/=E7 =CD=DF=EA=EF=F2 =C1=EB=E5=EE=FC=F0=EF=F5=EB=EF=F2 =DD=E3= =F1=E1=F8=E5:
Is there someway to write the following line even better with the

ability to detect daylight saving time by itself so i don't have to
alter the line manually when time changes?

lastvisit =3D ( datetime.utcnow() + timedelta(hours=3D2) ).strftime(
'%y-%m-%d %H:%M:%S' ) =A0 =A0 =A0 =A0# MySQL datetime format

Thanks.


Example:

#check if date entered as intented, format it properly for MySQL
lastvisit =3D datetime.strptime(lastvisit, '%d %m %Y').strftime(= 9;%Y-%m-%d')

The above code gets the datetime string in a specific way and then convert = it to another format. All happens in one line clear and simple.

Now, in the following statement there shopuld be some way to check for dayl= ight saving time so i would aboiut add +2 in winter or +3 for greek summer = time.


lastvisit =3D ( datetime.utcnow() + timedelta(hours=3D2) ).strftime( '%= y-%m-%d %H:%M:%S' ) =A0 =A0 =A0 =A0 =A0# MySQL datetime format

I think + timedelta(hours=3D2) should be substituted with something else bu= t i don't with what.
--
https://mail.python.org/mailman/listinfo/python-list

--047d7b5d98ab4f63d504eafa43aa--