Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Date strftime('%d%m%y') date to be of yesterday

12 views
Skip to first unread message

Tim Golden

unread,
Oct 22, 2009, 6:14:46 AM10/22/09
to pytho...@python.org
baboucarr sanneh wrote:
>
> Hi all
>
> I want to output the date of the with this format strftime('%d%m%y') but the date ie '%d' should be the date of yesterday
> eg
>
> import time
> strftime('%d%m%y') # something like minus a day..
> Thank you..am a newbie to python


<code>
import datetime
yesterday = datetime.date.today () - datetime.timedelta (days=1)
print yesterday.strftime ("%d%m%y")
</code>

TJG

Tim Golden

unread,
Oct 22, 2009, 6:36:50 AM10/22/09
to pytho...@python.org
baboucarr sanneh wrote:
>
> Hi tim,
>
> well i tried what your script but i do have an error

>>>> import datetime
>>>> yesterday = datetime.date.today () - datetime.timedelta (days=1)
>>>> print yesterday.strftime ("%d%m%y")
> SyntaxError: invalid syntax (<pyshell#2>, line 1)
>
> when i jus check the variable i.e yesterday i do get the out put but its in a different format
> datetime.date(2009, 10, 21)
> it seems like the conversion that is where the error is coming form
>
> I want it to be like 211009
>
> Thank you


I assume you're running Python 3.1? Try this:

print (yesterday.strftime ("%d%m%y"))

TJG

Tim Golden

unread,
Oct 22, 2009, 6:51:08 AM10/22/09
to pytho...@python.org
baboucarr sanneh wrote:
>
> Hi tim
>
> Thank you very much ...I have got it now..now i can continue with the backup script i want to make


By the way, the convention on this list is to bottom-post,
that is to add your comments / reply to the bottom of the
post you're replying to. These things vary from one place
to another, but it's only courteous to follow the local
customs :)

TJG

D'Arcy J.M. Cain

unread,
Oct 22, 2009, 9:30:03 AM10/22/09
to baboucarr sanneh, pytho...@python.org
On Thu, 22 Oct 2009 10:56:07 +0000
baboucarr sanneh <sann...@hotmail.com> wrote:
> > By the way, the convention on this list is to bottom-post,
>
> okay i got that will be doing so from now on :)....thnx

Thanks but what the previous poster forgot to mention was that you
should also trim the text that you are replying to. Notice how I
trimmed everything up to now down to two lines. This gives you the
gist of the conversation so far but makes it easier to read. People
reading the exchange will get enough out of the above to remind
themselves where we are in the conversation and if necessary they can
simply go back and read the entire thread in the archives.

--
D'Arcy J.M. Cain <da...@druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

0 new messages