943,955 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 365
  • Python RSS
Feb 12th, 2009
0

displaying date problem

Expand Post »
i need to be able to have python spit out a date like this (mm/dd/yyyy) even if the user doesnt add the "/" to there input. here is what i got so far.

import string
date = raw_input(enter your date:")
print date[0:2]+'/',date[2:4]+'/',date[4:8]

the output is mm/ dd/ yyyy.

how would you go about getting rid of the blank spaces in front of dd and yyyy?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
apollo1492 is offline Offline
9 posts
since Feb 2009
Feb 13th, 2009
0

Re: displaying date problem

Replace the commas by plus.
What do you expect the user to enter? You may want to give some kind of a templet/hint in your prompt.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Feb 13th, 2009
0

Re: displaying date problem

I would assign your date variable into a date type variable (I think it was something like datetime just look it up). so you will have a real date. then you can easiliy format your out put.
Reputation Points: 31
Solved Threads: 5
Light Poster
yilmazhuseyin is offline Offline
48 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Redirect(link) code in Python
Next Thread in Python Forum Timeline: Strip u' Unicode character from List





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC