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


Groups > comp.lang.python > #59189

Re: datetime question

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 <vtxvtx@gmail.com>
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&gt;': 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 <l5sv4a$a2$1@dont-email.me>
References <l5jk15$de$1@dont-email.me> <l5sv4a$a2$1@dont-email.me>
From Andy Lawton <andy@andylawton.eu>
Date Tue, 12 Nov 2013 12:47:58 +0000
X-Google-Sender-Auth LLpyoaa4srpltuUubhez_WKDjDw
Subject Re: datetime question
To Ferrous Cranus <nikos.gr33k@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2459.1384260501.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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 = pytz.timezone(zonename)
    now = pytz.utc.localize(datetime.utcnow())
    return now.astimezone(tz).dst() != timedelta(0)

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

lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
'%y-%m-%d %H:%M:%S' )


On 12 November 2013 10:15, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:

> Στις 8/11/2013 11:11 μμ, ο/η Νίκος Αλεξόπουλος έγραψε:
>
>> 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 = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
>> '%y-%m-%d %H:%M:%S' )        # MySQL datetime format
>>
>> Thanks.
>>
>
>
> Example:
>
> #check if date entered as intented, format it properly for MySQL
> lastvisit = datetime.strptime(lastvisit, '%d %m %Y').strftime('%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
> daylight saving time so i would aboiut add +2 in winter or +3 for greek
> summer time.
>
>
> lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime( '%y-%m-%d
> %H:%M:%S' )          # MySQL datetime format
>
> I think + timedelta(hours=2) should be substituted with something else but
> i don't with what.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

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


Thread

datetime question Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-11-08 23:11 +0200
  Re: datetime question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-08 21:29 +0000
    Re: datetime question Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-11-09 00:01 +0200
      Re: datetime question Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-08 17:06 -0500
        Re: datetime question rurpy@yahoo.com - 2013-11-11 14:49 -0800
          Re: datetime question Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-11 18:18 -0500
      Re: datetime question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-08 22:18 +0000
      Re: datetime question Grant Edwards <invalid@invalid.invalid> - 2013-11-08 22:29 +0000
        Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-09 09:39 +1100
          Re: datetime question Roy Smith <roy@panix.com> - 2013-11-09 10:30 -0500
        Re: datetime question Gene Heskett <gheskett@wdtv.com> - 2013-11-09 10:39 -0500
        Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-10 09:25 +1100
      Re: datetime question Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-08 22:49 +0000
        Re: datetime question Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-11-09 01:02 +0200
          Re: datetime question Robert Kern <robert.kern@gmail.com> - 2013-11-08 23:23 +0000
          Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-09 10:30 +1100
          Re: datetime question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-09 00:12 +0000
          Re: datetime question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-09 12:45 +0000
            Re: datetime question Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-11-09 15:43 +0200
              Re: datetime question unknown <unknown@unknown.com> - 2013-11-10 12:52 +0000
          Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-09 23:52 +1100
  Re: datetime question Gene Heskett <gheskett@wdtv.com> - 2013-11-09 19:55 -0500
  Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-10 19:47 +1100
  Re: datetime question Gene Heskett <gheskett@wdtv.com> - 2013-11-10 04:13 -0500
  Re: datetime question Νίκος Αλεξόπουλος <nikos.gr33k@gmail.com> - 2013-11-11 11:57 +0200
    Re: datetime question Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-11 08:41 -0500
      Re: datetime question Roy Smith <roy@panix.com> - 2013-11-11 09:14 -0500
        Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-12 01:25 +1100
        Re: datetime question Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-11 09:36 -0500
        Re: datetime question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-11 20:59 -0500
        Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-12 13:02 +1100
        Re: datetime question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-11 21:02 -0500
        Re: datetime question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-12 19:30 -0500
        Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-13 11:40 +1100
    Re: datetime question Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-11 19:19 +0000
      Re: datetime question Ethan Furman <ethan@stoneleaf.us> - 2013-11-11 11:39 -0800
        Re: datetime question Grant Edwards <invalid@invalid.invalid> - 2013-11-11 20:45 +0000
        Re: datetime question mm0fmf <none@mailinator.com> - 2013-11-11 23:21 +0000
          Re: datetime question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-11 23:48 +0000
            Re: datetime question Grant Edwards <invalid@invalid.invalid> - 2013-11-12 04:49 +0000
              Re: datetime question alex23 <wuwei23@gmail.com> - 2013-11-12 17:25 +1000
                Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-12 18:35 +1100
                Re: datetime question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-12 09:20 +0000
              Re: datetime question Roy Smith <roy@panix.com> - 2013-11-12 09:18 -0500
  Re: datetime question Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-11-12 12:15 +0200
    Re: datetime question Andy Lawton <andy@andylawton.eu> - 2013-11-12 12:47 +0000
      Re: datetime question Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-11-12 15:32 +0200
        Re: datetime question Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-12 09:03 -0500
          Re: datetime question Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-11-12 16:12 +0200
            Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-13 01:57 +1100
              Re: datetime question Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-11-12 17:24 +0200
                Re: datetime question Tim Chase <python.list@tim.thechases.com> - 2013-11-12 09:54 -0600
                Re: datetime question Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-11-12 17:57 +0200
                Re: datetime question Tim Chase <python.list@tim.thechases.com> - 2013-11-12 10:12 -0600
                Re: datetime question William Ray Wing <wrw@mac.com> - 2013-11-12 11:14 -0500
                Re: datetime question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-12 16:30 +0000
                Re: datetime question MRAB <python@mrabarnett.plus.com> - 2013-11-12 19:09 +0000
                Re: datetime question Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-12 14:14 -0500
                Re: datetime question Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-12 19:24 +0000
                Re: datetime question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-12 19:38 -0500
                Re: datetime question Chris Angelico <rosuav@gmail.com> - 2013-11-13 09:42 +1100
                Re: datetime question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-12 19:37 -0500
                Re: datetime question MRAB <python@mrabarnett.plus.com> - 2013-11-13 01:08 +0000
                Re: datetime question Alister <alister.ware@ntlworld.com> - 2013-11-12 16:11 +0000
                Re: datetime question Roy Smith <roy@panix.com> - 2013-11-12 19:43 -0500
      Re: datetime question Denis McMahon <denismfmcmahon@gmail.com> - 2013-11-12 19:20 +0000

csiph-web