Python DateTime Manipulation

K

Kingston

I have a user input a date and time as a string that looks like:
"200901010100" but I want to do a manipulation where I subtract 7 days
from it.

The first thing I tried was to turn the string into a time with the
format "%Y%m%d%H%M" and then strip out the day value, turn it into an
int and subtract seven, but the value "-6" doesn't mean anything in
terms of days =).

Does anyone have an idea as to how I can subtract 7 days without
turning the date string into an int?

Perfect Scenario:
perfectdate = 200901010100 - 7Days
print perfect date
200812250100


What I have so far:
import time, os, re
useryear = raw_input("Enter Year (numerical YYYY): ")
usermonth = raw_input("Enter Month (numerical MM): ")
userday = raw_input("Enter Day (numerical DD): ")
usertime = raw_input("Enter Time (24-hour clock hhmm): ")
#userday = int(userday)
#secondday = userday - 07
#secondday = str(secondday)
#userday = str(userday)
#firstdate = useryear + usermonth + secondday + usertime
seconddate = useryear + usermonth + userday + usertime
seconddate = time.strptime(seconddate, %Y%m%d%H%M)
print seconddate
 
C

Chris Rebert

I have a user input a date and time as a string that looks like:
"200901010100" but I want to do a manipulation where I subtract 7 days
from it.

The first thing I tried was to turn the string into a time with the
format "%Y%m%d%H%M" and then strip out the day value, turn it into an
int and subtract seven, but the value "-6" doesn't mean anything in
terms of days =).

Does anyone have an idea as to how I can subtract 7 days without
turning the date string into an int?
datetime.datetime(2009, 1, 8, 14, 22, 56, 416662)


Cheers,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top