nikos.gr33k at gmail.com
Tue Nov 12 11:15:38 CET 2013
Στις 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
#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
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.
More information about the Python-list